fix: remove lru_cache memory leak in Repository.is_git_repo #4212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: remove lru_cache memory leak in Repository.is_git_repo
Fixes #4210
The @lru_cache decorator on instance methods causes memory leaks because
the cache holds references to self, preventing garbage collection. I found
this issue with a TODO comment acknowledging the problem but no fix.
My solution uses instance-level caching (self._is_git_repo_cache) which
provides the same performance benefit without the memory leak.
This affects anyone running long-lived processes or automation scripts that
repeatedly check git repos. The memory leak is gradual but adds up over time.
Closes #4210
Note
Fix memory leak in
Repository.is_git_repo@lru_cachewith per-instance_is_git_repo_cacheto avoid retainingselfand reduce subprocess calls_is_git_repo_cacheinRepository.__init__/is_git_repo; behavior remains unchangedlru_cacheimportWritten by Cursor Bugbot for commit d96af9e. This will update automatically on new commits. Configure here.