Hi,
I am using panda3d for machine learning purpose, so I need to update the model’s position manually. But I find memory leaks fast when I run the following code, both in 1.9 and 1.10.
from panda3d.core import NodePath
ralph = NodePath('r')
while True:
h = ralph.getH()
ralph.setH(h + 1)
Is it designed to work in this way, so I need to rewrite the code to avoid memory leaking? Or is it a bug that can be fixed?
It is not a bug; Panda caches scene graph transformations for performance reasons. The transform cache is garbage collected once per frame, which is usually enough (it is rare to do tens of thousands of transforms per frame).
There are two ways to avoid this. First is to disable the transform cache altogether:
from panda3d.core import NodePath, loadPrcFileData
loadPrcFileData("", "transform-cache false")
ralph = NodePath('r')
while True:
h = ralph.getH()
ralph.setH(h + 1)
Second is to garbage collect it periodically:
from panda3d.core import NodePath, TransformState
ralph = NodePath('r')
while True:
h = ralph.getH()
ralph.setH(h + 1)
TransformState.garbageCollect()
Note that you normally don’t need to call this as Panda calls it every frame.