Browse Source

fix memory leak

Darren Ranalli 17 years ago
parent
commit
d5d23c2fa7
2 changed files with 33 additions and 0 deletions
  1. 31 0
      direct/src/task/TaskNew.py
  2. 2 0
      panda/src/event/pythonTask.cxx

+ 31 - 0
direct/src/task/TaskNew.py

@@ -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

+ 2 - 0
panda/src/event/pythonTask.cxx

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