Skip to content

memory leak in Tree.join() #289

Closed
Closed
@hvnsweeting

Description

@hvnsweeting

Hello,
I'm not a direct user of gitpython but I used it as a backend of saltstack gitfs fileserver:

Due to the mem leak problem in this issue:
saltstack/salt#17006 (comment)

I traced down the memleak happen in multiple places:

  1. https://github.com/saltstack/salt/blob/develop/salt/fileserver/gitfs.py#L1453
  2. https://github.com/saltstack/salt/blob/develop/salt/fileserver/gitfs.py#L1151

for 1, I used memory_profiler to help showing memleak, here are some results:
https://github.com/gitpython-developers/GitPython/blob/master/git/objects/tree.py#L180

170  70.3359 MiB   0.0000 MiB           if '/' in file:
   171                                         tree = self
   172                                         item = self
   173                                         tokens = file.split('/')
   174                                         for i, token in enumerate(tokens):
   175                                             item = tree[token]
   176                                             if item.type == 'tree':
   177                                                 tree = item
   178                                             else:
   179                                                 # safety assertion - blobs are at the end of the path
   180                                                 if i != len(tokens) - 1:
   181                                                     raise KeyError(msg % file)
   182
   183                                                 print item, dir(item) # added by me
   184                                                 return item
   185                                             # END handle item type
   186                                         # END for each token of split path
   187                                         if item == self:
   188                                             raise KeyError(msg % file)
   189                                         return item
   190                                     else:
   191  70.3438 MiB   0.0078 MiB               for info in self._cache:
   192  70.3438 MiB   0.0000 MiB                   if info[2] == file:     # [2] == name

And:

201929    174  61.0586 MiB   0.0000 MiB               for i, token in enumerate(tokens):
201930    175                                             item = tree[token]
201931    176  61.0625 MiB   0.0039 MiB                   if item.type == 'tree':
201932    177  61.0586 MiB  -0.0039 MiB                       tree = item
201933    178                                             else:
201934    179                                                 # safety assertion - blobs are at the end of the path
201935    180                                                 # if i != len(tokens) - 1: I commented them out
201936    181                                                 #     raise KeyError(msg % file)
201937    182  61.0625 MiB   0.0039 MiB                       return item

I'm using:

GitPython==1.0.1

it's not clear to me why it leaked, could you please help me to figure it out / give a fix for it.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions