ISceneManager smgr = ..
//build the scene graph, have fun, keep referenced to important scene nodes, etc.
//decide to reset scene graph (change level)
smgr->clear();
//build new scene graph and have more fun
Do I have to also drop the references to the old scene graph and reset them to nullptr, or does that happen automatically?
If I don't drop my references and just reassign them to new scene nodes from the newly created level, do I have a memory leak?
Irrlicht uses reference-counting. If you want to take part in that you have to do it explicitely. So you if you have a node and say myNode->grab() - then you increase the reference count and the node will stay in memory even after a clear() until you call myNode->drop(). If you don't do that then the node will be removed, but you then have to be careful to not use your pointer anymore after a clear() as it will now point to invalid memory.
So if I don't use grab, I don't need to use drop after the clear() function?
If I understand correctly, functions which have create as part of their name increase the ref count - are they deleted after clear() provided i did not call grab, or do I have to make sure I drop them after I'm done with them?
And what about something like getMesh? do I have to grab it for it to remain after clear()?
Functions which start with create act the same way as if you call grab() once. Meaning their reference-counter starts with 1 instead of 0. Aside from that - it's simply a counter. The objects are deleted when the counter is zero. Irrlicht increases and decreases the counter for it's own classes (like SceneManager) and leaves it up to you if you want to use the Irrlicht mechanism as well or not.
Meshes and Textures have the same mechanism. But they are additionally cached in the MeshCache and TextureCache which grabs an additional reference. They stay in there unless you explicitely remove them from the caches.
I understand it's just a counter.. I just want to make sure I got it correctly:
If I use a create function to get an animator node, add it to another node, and than call clear on scene manager - I would still have that animator node because it had 2 refs, and now it has one? So I have to drop the animator or it would leak?
Just making sure of when to use the RAII wrapper...
Yes, you got that correct. When you have a pointer you got from a function that starts with 'create' then you always have to call drop() at some point or you get a memory leak.