In a very large project I'm searching for a memory leak. Here my progress so far:
Using a class counter,
import gc
from collections import Counter
def count():
return Counter(type(o).__name__ for o in gc.get_objects())
I see that for each render pass of the program I gain dicts and instancemethods:
Counter({'instancemethod': 9714, 'dict': 7274, ...
Counter({'instancemethod': 9716, 'dict': 7275, ...
Counter({'instancemethod': 9718, 'dict': 7276, ...
Counter({'instancemethod': 9720, 'dict': 7277, ...
I then tried to identify the additional dict that isn't getting garbage collected, with this:
def get_latest():
for e in gc.get_objects():
if type(e).__name__ == "dict":
latest = e
return latest
Unfortunately, that returns mostly the identical (dict1 is dict2), so it's not the last in the list.
Any pointers on how to find the leak would be appreciated. Using python 2.7 and bleeding edge pyglet.
Also, this only affects the game's client, not the server. So It may be a problem within pyglet - even so I would like to find it.
EDIT: This question is answered by myself, my problem was using pyglet's push_handlers method each frame as opposed to once.
My problem was using pyglet's push_handlers method each frame as opposed to once. Removing that, the memory leak is gone.