Python will automatically garbage collect a custom class instance when all the references to that instance are removed. In theory, this makes garbage collection as simple as cleaning up those references, but because there are so many different places and reasons for these references, garbage collection can quickly grow complicated. Following these steps will help to ensure that a custom class instance is properly garbage collected.
Call
removeNode
on allNodePaths
in the scene graph—the first step is to clear out theNodePaths
that the custom class has added to the scene graph. If this step isn't accomplished, it won't necessarily prevent the custom class instance from being garbage collected, but it could. Even if the custom class instance is still garbage collected, the scene graph itself will retain references to theNodePaths
that haven't been cleared out and they will remain in the scene graph. There is one exception to this rule: when a parentNodePath
hasremoveNode...