mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
added GarbageLeakDetector
This commit is contained in:
parent
83b5b73359
commit
657792498a
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user