Skip to content

Commit 454feda

Browse files
author
James E. Blair
committed
Only gc.collect() under windows
Under Windows, tempfile objects are holding references to open files until the garbage collector closes them and frees them. Explicit calls to gc.collect() were added to the finalizer for the Repo class to force them to be closed synchronously. However, this is expensive, especially in large, long-running programs. As a temporary measure to alleviate the performance regression on other platforms, only perform these calls when running under Windows. Fixes #553
1 parent f237620 commit 454feda

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: git/repo/base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,17 @@ def __del__(self):
209209
def close(self):
210210
if self.git:
211211
self.git.clear_cache()
212-
gc.collect()
212+
# Tempfiles objects on Windows are holding references to
213+
# open files until they are collected by the garbage
214+
# collector, thus preventing deletion.
215+
# TODO: Find these references and ensure they are closed
216+
# and deleted synchronously rather than forcing a gc
217+
# collection.
218+
if is_win:
219+
gc.collect()
213220
gitdb.util.mman.collect()
214-
gc.collect()
221+
if is_win:
222+
gc.collect()
215223

216224
def __eq__(self, rhs):
217225
if isinstance(rhs, Repo):

0 commit comments

Comments
 (0)