2012-07-07 54 views
0

在一个非常大的项目中,我正在寻找内存泄漏。在这里我迄今取得的进展:Python(w/pyglet)内存泄漏

使用类柜台,

import gc 
from collections import Counter 
def count(): 
     return Counter(type(o).__name__ for o in gc.get_objects()) 

我看到,每个渲染程序的通我收获类型的字典和instancemethods:

Counter({'instancemethod': 9714, 'dict': 7274, ... 
Counter({'instancemethod': 9716, 'dict': 7275, ... 
Counter({'instancemethod': 9718, 'dict': 7276, ... 
Counter({'instancemethod': 9720, 'dict': 7277, ... 

然后我试图找出额外的字典,没有得到垃圾收集,与此:

def get_latest(): 
    for e in gc.get_objects(): 
     if type(e).__name__ == "dict": 
      latest = e 
    return latest 

不幸的是,返回大部分是相同的(dict1是dict2),所以它不是列表中的最后一个。

任何指针如何找到泄漏将不胜感激。 使用python 2.7和边缘pyglet。

此外,这只影响游戏的客户端,而不是服务器。所以这可能是pyglet中的一个问题 - 即使如此我也想找到它。

编辑:这个问题是由我自己回答的,我的问题是使用pyglet的push_handlers方法每帧相对于一次。

回答

0

我的问题是每次使用pyglet的push_handlers方法而不是一次。除去那个,内存泄漏消失了。