Skip to content

Commit

Permalink
fix(leaks): repo context-man to cleanup global mman on repo-delete
Browse files Browse the repository at this point in the history
Improve API for problems like #553.
  • Loading branch information
ankostis committed Dec 8, 2016
1 parent 2f207e0 commit f1a82e4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import os.path as osp

from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch
import gc
import gitdb


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -177,9 +179,21 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
args.append(self.git)
self.odb = odbt(*args)

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()

def __del__(self):
self.close()

def close(self):
if self.git:
self.git.clear_cache()
gc.collect()
gitdb.util.mman.collect()
gc.collect()

def __eq__(self, rhs):
if isinstance(rhs, Repo):
Expand Down

0 comments on commit f1a82e4

Please sign in to comment.