Hi,
recently I found out that removeNode() only removes one particular node and all children are still there and only dispatched.
Consider the following code
import direct.directbase.DirectStart
from pandac.PandaModules import NodePath as NP
class C(object):
def __init__(self):
a = render.attachNewNode("a")
aa = a.attachNewNode("aa")
aaa = aa.attachNewNode("aaa")
smiley = loader.loadModel("smiley")
smiley.reparentTo(aaa)
print "-"*10
print "a = "+str(NP(a))
print "aa = "+str(NP(aa))
print "aaa = "+str(NP(aaa))
print "smiley = "+str(smiley)
print "-"*10
render.ls()
print "-"*10
print "removing aa"
aa.removeNode()
print "-"*10
print "a = "+str(NP(a))
print "aa = "+str(NP(aa))
print "aaa = "+str(NP(aaa))
print "smiley = "+str(smiley)
print "-"*10
c = C()
render.ls()
#run()
It recults in
----------
a = render/a
aa = render/a/aa
aaa = render/a/aa/aaa
smiley = render/a/aa/aaa/smiley.egg
----------
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib)
ModelNode camera
Camera cam ( PerspectiveLens )
PerspectiveLens fov = 39.3201 30
PandaNode a
PandaNode aa
PandaNode aaa
ModelRoot smiley.egg
GeomNode (1 geoms: S:(TextureAttrib))
----------
removing aa
----------
a = render/a
aa = **removed**
aaa = aa/aaa
smiley = aa/aaa/smiley.egg
----------
PandaNode render S:(CullFaceAttrib RescaleNormalAttrib)
ModelNode camera
Camera cam ( PerspectiveLens )
PerspectiveLens fov = 39.3201 30
PandaNode a
Now what you notice is that the loaded smiley is still there and thus won’t be cleaned up, still consuming memory. Correct me if I’m wrong here.
How about a method like removeNodes() (or removeNodeAndChildren() or removeNodeRecursively()) that goes through all the children of a node and removes those before removing the actual node?
I think this would be quite useful.
Imagine you have everything stored under a node called “foo”, which is direct ancestor of render. If you want to restart everythig or move on to another part of the game, you could simply call one function on “foo” and everything would be cleaned up implicitly.