fix memory leak

This commit is contained in:
Darren Ranalli 2009-02-04 00:10:38 +00:00
parent fec518af71
commit d5d23c2fa7
2 changed files with 33 additions and 0 deletions

View File

@ -1199,3 +1199,34 @@ class TaskManager:
del l
tm.destroy()
del tm
if __debug__:
def checkLeak():
import sys
import gc
gc.enable()
from direct.showbase.DirectObject import DirectObject
class TestClass(DirectObject):
def doTask(self, task):
return task.done
obj = TestClass()
startRefCount = sys.getrefcount(obj)
print 'sys.getrefcount(obj): %s' % sys.getrefcount(obj)
print '** addTask'
t = obj.addTask(obj.doTask, 'test')
print 'sys.getrefcount(obj): %s' % sys.getrefcount(obj)
print 'task.getRefCount(): %s' % t.getRefCount()
print '** removeTask'
obj.removeTask('test')
print 'sys.getrefcount(obj): %s' % sys.getrefcount(obj)
print 'task.getRefCount(): %s' % t.getRefCount()
print '** step'
taskMgr.step()
taskMgr.step()
taskMgr.step()
print 'sys.getrefcount(obj): %s' % sys.getrefcount(obj)
print 'task.getRefCount(): %s' % t.getRefCount()
print '** task release'
t = None
print 'sys.getrefcount(obj): %s' % sys.getrefcount(obj)
assert sys.getrefcount(obj) == startRefCount

View File

@ -64,6 +64,8 @@ PythonTask::
Py_DECREF(_args);
Py_DECREF(_dict);
Py_XDECREF(_generator);
Py_XDECREF(_owner);
Py_XDECREF(_upon_death);
}
////////////////////////////////////////////////////////////////////