{"action":"opened","issue":{"url":"https://api.github.com/repos/gitpython-developers/GitPython/issues/289","labels_url":"https://api.github.com/repos/gitpython-developers/GitPython/issues/289/labels{/name}","comments_url":"https://api.github.com/repos/gitpython-developers/GitPython/issues/289/comments","events_url":"https://api.github.com/repos/gitpython-developers/GitPython/issues/289/events","html_url":"https://github.com/gitpython-developers/GitPython/issues/289","id":82261886,"number":289,"title":"memory leak in Tree.join()","user":{"login":"hvnsweeting","id":1000665,"avatar_url":"https://avatars.githubusercontent.com/u/1000665?v=3","gravatar_id":"","url":"https://api.github.com/users/hvnsweeting","html_url":"https://github.com/hvnsweeting","followers_url":"https://api.github.com/users/hvnsweeting/followers","following_url":"https://api.github.com/users/hvnsweeting/following{/other_user}","gists_url":"https://api.github.com/users/hvnsweeting/gists{/gist_id}","starred_url":"https://api.github.com/users/hvnsweeting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hvnsweeting/subscriptions","organizations_url":"https://api.github.com/users/hvnsweeting/orgs","repos_url":"https://api.github.com/users/hvnsweeting/repos","events_url":"https://api.github.com/users/hvnsweeting/events{/privacy}","received_events_url":"https://api.github.com/users/hvnsweeting/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-29T04:53:12Z","updated_at":"2015-05-29T04:53:12Z","closed_at":null,"body":"Hello,\r\nI'm not a direct user of gitpython but I used it as a backend of saltstack gitfs fileserver:\r\n\r\nDue to the mem leak problem in this issue:\r\nhttps://github.com/saltstack/salt/issues/17006#issuecomment-105140321\r\n\r\nI traced down the memleak happen in multiple places:\r\n\r\n# https://github.com/saltstack/salt/blob/develop/salt/fileserver/gitfs.py#L1453\r\n# https://github.com/saltstack/salt/blob/develop/salt/fileserver/gitfs.py#L1151\r\n\r\nfor 1, I used memory_profiler to help showing memleak, here are some results:\r\n\r\n````\r\n170  70.3359 MiB   0.0000 MiB           if '/' in file:\r\n   171                                         tree = self\r\n   172                                         item = self\r\n   173                                         tokens = file.split('/')\r\n   174                                         for i, token in enumerate(tokens):\r\n   175                                             item = tree[token]\r\n   176                                             if item.type == 'tree':\r\n   177                                                 tree = item\r\n   178                                             else:\r\n   179                                                 # safety assertion - blobs are at the end of the path\r\n   180                                                 if i != len(tokens) - 1:\r\n   181                                                     raise KeyError(msg % file)\r\n   182\r\n   183                                                 print item, dir(item) # added by me\r\n   184                                                 return item\r\n   185                                             # END handle item type\r\n   186                                         # END for each token of split path\r\n   187                                         if item == self:\r\n   188                                             raise KeyError(msg % file)\r\n   189                                         return item\r\n   190                                     else:\r\n   191  70.3438 MiB   0.0078 MiB               for info in self._cache:\r\n   192  70.3438 MiB   0.0000 MiB                   if info[2] == file:     # [2] == name\r\n````\r\n\r\nAnd:\r\n\r\n````\r\n201929    174  61.0586 MiB   0.0000 MiB               for i, token in enumerate(tokens):\r\n201930    175                                             item = tree[token]\r\n201931    176  61.0625 MiB   0.0039 MiB                   if item.type == 'tree':\r\n201932    177  61.0586 MiB  -0.0039 MiB                       tree = item\r\n201933    178                                             else:\r\n201934    179                                                 # safety assertion - blobs are at the end of the path\r\n201935    180                                                 # if i != len(tokens) - 1: I commented them out\r\n201936    181                                                 #     raise KeyError(msg % file)\r\n201937    182  61.0625 MiB   0.0039 MiB                       return item\r\n````\r\n\r\nI'm using:\r\n\r\n````\r\nGitPython==1.0.1\r\n````\r\n\r\nit's not clear to me why it leaked, could you please help me to figure it out / give a fix for it. \r\nThanks"}}