Just wondering the correct way to unload a scene for freeing up memory.
Currently I am using the following function to destroy things, I passed a scene node to it and destroy everything under the node.
But it doesn't work as I expected, the meshes did disappear and got removed from the scene tree but the memory usage didn't go down.
Code: Select all
void DestroyItemRecursively(Ogre::SceneNode* node, Ogre::SceneManager* sceneManager)
{
auto count = node->numAttachedObjects();
std::vector<Ogre::MovableObject*> attachObjects;
attachObjects.reserve(count);
for (auto i = 0; i < count; ++i)
{
Ogre::MovableObject* movable = node->getAttachedObject(i);
attachObjects.push_back(movable);
}
node->detachAllObjects();
for (Ogre::MovableObject* movable : attachObjects)
{
sceneManager->destroyMovableObject(movable);
}
for (int i = 0; i < node->numChildren(); ++i)
{
Ogre::SceneNode* child = static_cast<Ogre::SceneNode*>(node->getChild(i));
DestroyItemRecursively(child, sceneManager);
}
node->removeAndDestroyAllChildren();
}
Do I have to remove Hlms materials and textures from the resource managers by their name manually?
Is there any way I can remove the unused materials and textures automatically?
Thanks.
