Is it okay to first load a model using loader.loadModel() and then later change the model by calling loadModel() again on the same object. I mean, is it safe to do this without calling some unloader function:
obj = loader.loadModel("foo.egg")
# Do stuff...
obj = loader.loadModel("bar.egg")
This is probably a stupid question, but I was just wondering about it. I have read that Python handles garbage collection but I guess I’m just so used to C++ that I can’t trust it enough, and also I don’t know if Panda uses some special loading mechanisms.
Rember that the object is in the render tree.
You are only chaning a variable which is pointing to a node in the Rendertree(if its in the render tree)
Sorry, I’m not totally sure I understand. Does that mean that when I call loadModel(), a new node is created in the render tree, and that if I assign the “obj” variable to another node, then the old node is left hanging in the tree and unreleased? Or is it automatically deallocated at some point?
The rule is this: when you reassign a model’s handle, the model will get deallocated if it is does not currently have a parent node. If it does have a parent node, it will stick around until its parent node is deallocated.
That is to say, if you have parented the model to the render (via obj.reparentTo(render) or some such), and it is still there when you reassign obj, then it will remain there forever. If you have parented the model to some other node (for instance, obj.reparentTo(myOtherNode)), then it will remain there as long as myOtherNode remains there (which might be forever, or maybe you’re about to remove it in the next command).
If you have never parented the model anywhere, or you have parented it but later you removed it by calling obj.removeNode() or obj.detach(), then when you reassign obj, it will get deallocated automatically.
If you have any doubts as to whether the object has a parent and you want to be sure it is deallocated, you should call obj.removeNode().
Ok, thanks David. I was wondering about removeNode() but wasn’t sure. Now I got it.