Skip to content

Remote objects are never destroyed, which means Repository is never destroyed #403

Closed
@mduggan

Description

@mduggan

This is a similar issue to #321 #326 #328, but the cause is different

When I do this:

import pygit2, sys
repo = pygit2.Repository('libgit2')
print "refcount before: %d" % sys.getrefcount(repo)
for i in range(1,100):
    len(repo.remotes)

print "refcount after: %d" % sys.getrefcount(repo)

I get this:

~/src$ python testgit.py 
refcount before: 2
refcount after: 101

The root cause is the self._self_handle in the Remote object. Because it's an opaque reference through ffi, it seems that the python garbage collector can't detect the circular reference of the Remote to itself. That means it never gets cleaned up, and it leaks a reference to the repo in self._repo, so that never gets cleaned up either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions