When I want to get rid of an object in my scene, I detach the scene node and the entity for its mesh. If I don't destroy the entity I start to see a performance hit pretty quickly, but I don't see any difference when I don't destroy the scene node. So what happens to scene nodes that aren't attached to anything? I get that they don't take up processing time because they're no longer processed by the scene manager, but are they still taking up memory? If I'm rapidly adding and removing a lot of objects from the scene should I make sure to destroy unused scene nodes to free up the memory, or does Ogre recycle them automatically. Also, why do I see my framerate drop if I leave entities around? are they still being processed in some way?
For the record I'm using Ogre 2.0, though I expect this is all applicable to 1.x versions as well.
For future reference, if I have further questions about the internal workings of Ogre, where would be the best place to post? I guessed at the user forums, but I'd also understand if the developer forums were preferred.
What Happens to Unused Scene Nodes?
- excaliburHisSheath
- Gnoblar
- Posts: 18
- Joined: Sat Feb 15, 2014 8:06 pm
- excaliburHisSheath
- Gnoblar
- Posts: 18
- Joined: Sat Feb 15, 2014 8:06 pm
Re: What Happens to Unused Scene Nodes?
After a very cursory examination, it looks like not destroying unused scene nodes "leaks" memory. I put "leaks" in quotes because Ogre still holds on to the memory for those nodes and will reclaim it if you switch scenes, but that memory will be lost for the lifetime of the current scene. If this is the case, why does the documentation for SceneManager::DestroySceneNode() recommend not manually destroying the nodes? Is it simply because it's rare that enough nodes will be created and destroyed over the lifetime of a scene to have a significant impact on memory? Is there a performance hit to destroying scene nodes? I didn't notice one in my testing.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: What Happens to Unused Scene Nodes?
It's probably recommend not to call SceneManager::destroySceneNode because most users will not need to do so, or you should plan another way around it.
I don't know your specific case, but for example if you have a machine gun where every bullet had its own SceneNode ... you would likely want to use a pool instead of creating and destroying nodes over and over. Then when you SceneManager::clearScene they will all get cleaned up at a time when it is not affecting performance, as opposed to cleaning them up piecemeal while the user is in the middle of gameplay.
I don't know your specific case, but for example if you have a machine gun where every bullet had its own SceneNode ... you would likely want to use a pool instead of creating and destroying nodes over and over. Then when you SceneManager::clearScene they will all get cleaned up at a time when it is not affecting performance, as opposed to cleaning them up piecemeal while the user is in the middle of gameplay.
- excaliburHisSheath
- Gnoblar
- Posts: 18
- Joined: Sat Feb 15, 2014 8:06 pm
Re: What Happens to Unused Scene Nodes?
Pooling the scene nodes is a good idea and is probably what I'll end up doing, though I'm still curious why it's recommended not to manually destroy them. I didn't notice a performance hit from destroying them, though my test case wasn't exactly robust. I'm curious if it becomes expensive to destroy large hierarchies of nodes every frame?
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: What Happens to Unused Scene Nodes?
I'm actually not sure how performance scales with scene complexity. One would think there would be a performance hit iterating through the SceneNodeList (based on the number of total nodes in the scene), but looking closer at the code, apparently each SceneNode stores their own index in that vector for fast removal (clever!). Also default memory management is done by nedpool, which reduces the performance hit from calls to delete.
Clearly using clearScene is less performance impacting if you can tolerate the "leaked" memory (not really leaked, but you know what I mean) from detached SceneNodes waiting to get cleaned up. But then again if you aren't having any performance issues from creating/destroying SceneNodes ... perhaps there is no reason to implement a pool. I'd do a pool anyway just out of the worry of some situation that could somehow cause OOM after someone leaves their character standing in front of a firing minigun for 6 hours
Clearly using clearScene is less performance impacting if you can tolerate the "leaked" memory (not really leaked, but you know what I mean) from detached SceneNodes waiting to get cleaned up. But then again if you aren't having any performance issues from creating/destroying SceneNodes ... perhaps there is no reason to implement a pool. I'd do a pool anyway just out of the worry of some situation that could somehow cause OOM after someone leaves their character standing in front of a firing minigun for 6 hours