How can we free game resources like models, textures, sounds, music, etc … so that we can be sure that the memory was actualy free?
Basically, in Python the structure is reference based, so an object will be terminated once it is not referenced any longer.
When you call NodePath.removeNode(), you’re removing that nodepath and all of it’s descendants from your scene, no matter their types. So, they are no longer exist in memory and the particular memory blocks that have been occupied are released. The simplest way to check if there is leakage, try to repetitively loading and removing any of your models, textures, sounds, music, etc for several hundred times, while performing memory monitoring in background. If there was leakage, you should be able to see your free memory drops. If your memory usage remains static, it means memory restoring was succesfully performed.
Read these :
https://discourse.panda3d.org/viewtopic.php?t=1588
https://discourse.panda3d.org/viewtopic.php?t=1650
Let me see if i understand, to dispose the memory used by a resource i have to make sure it isn’t referenced by any non-local variable in the game or panda data structure.
For example if the game loads a sound:
mySound1 = loader.loadSfx(“SoundFile.wav”)
I don’t have to tell the loader to forget about the sound, just do
mySound1 = None.
Can we force Python to do the ref checking with a command at a certain place in the code?
adding to ynjh_jo’s post: regarding Python you can also have a look at docs.python.org/lib/module-gc.html - Python is using reference counting AND a garbage collector
to get fully rid of a node, it’s model, and it’s textures (if model and textures are not referenced by any other node!), do:
for models:
# create
model = loader.loadModel(modelPath)
model.reparentTo(render)
...
# destruct
model.removeNode()
model = None
loader.unloadModel(modelPath)
actors are more compilcated, but this works as far as i know:
# create
actor = Actor()
actor.loadModel(modelPath)
actor.loadAnims(animations)
...
# destruct
children = actor.getGeomNode().getChildren()
children.detach()
actor.unloadAnims(animations)
actor = None
loader.unloadModel(modelPath)
do a
render.analyze()
before and after to see if this works for you.
(these are only code snippets, you have to adapt to your situation)
hope that helps,
kaweh
Ok i think i get it. Thanks.