added GarbageLeakDetector

This commit is contained in:
Darren Ranalli 2007-04-18 09:40:15 +00:00
parent 83b5b73359
commit 657792498a

View File

@ -1,6 +1,7 @@
# objects that report different types of leaks to the ContainerLeakDetector
import __builtin__
from direct.showbase.PythonUtil import gcDebugOn
import __builtin__, gc
class LeakDetector:
def __init__(self):
@ -12,6 +13,21 @@ class LeakDetector:
def destroy(self):
del leakDetectors[id(self)]
class GarbageLeakDetector(LeakDetector):
# are we accumulating Python garbage?
def __len__(self):
# do a garbage collection
wasOn = gcDebugOn()
oldFlags = gc.get_debug()
if not wasOn:
gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect()
numGarbage = len(gc.garbage)
del gc.garbage[:]
if not wasOn:
gc.set_debug(oldFlags)
return numGarbage
class SceneGraphLeakDetector(LeakDetector):
# is a scene graph leaking nodes?
def __init__(self, render):