Memory cleanup on iOS

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
chocoanzak
Kobold
Posts: 36
Joined: Wed Mar 28, 2012 2:00 pm

Memory cleanup on iOS

Post by chocoanzak »

I am running Ogre 1.9 on iOS on an iPad 4 and have experienced difficulty cleaning up the memory used when loading a model into Ogre.

To initialise it I use:
String pluginsPath;
// only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
pluginsPath = m_ResourcePath + "plugins.cfg";
#endif

m_pRoot = OGRE_NEW Ogre::Root(pluginsPath, m_ResourcePath + "ogre.cfg");

#ifdef OGRE_STATIC_LIB
m_StaticPluginLoader.load();
#endif

if(!m_pRoot->showConfigDialog()){
return false;

}
m_pRoot->initialise(false);

NameValuePairList misc;
/*misc["FSAA"] = "0";
misc["contentScalingFactor"] = "2";
misc["displayFrequency"] = "0";*/

misc["colourDepth"] = "32";
misc["contentScalingFactor"] = "2.0";
misc["FSAA"] = "0";

//misc["orientation"] = "Landscape Right";
//m_pRenderWnd = m_pRoot->createRenderWindow("OgreWindow",1536,2048,true,&misc);
m_pRenderWnd = m_pRoot->createRenderWindow("OgreWindow",768,1024,false,&misc);

m_pSceneMgr = m_pRoot->createSceneManager(ST_GENERIC, "SceneManager");
MeshManager::getSingletonPtr()->setBoundsPaddingFactor(0);
// Warm Flourescent 255, 244, 229
m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0));

//this->customiseEngine();

this->createViewports();

this->createResources();

m_pRoot->setFrameSmoothingPeriod(0);

m_pTimer = OGRE_NEW Ogre::Timer();
m_pTimer->reset();

m_pRenderWnd->setActive(true);

this->initializeRTShaderSystem(m_pSceneMgr);
this->setupShadows();
and I'm shutting it down with the following method:
m_PitchDestQuart.~Quaternion();
m_YawDestQuart.~Quaternion();
m_RollDestQuart.~Quaternion();

m_pRenderWnd->destroy();
m_pRenderWnd = NULL;

//m_pSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
//m_pSceneMgr->setShadowCameraSetup(0l);
//m_pSceneMgr->setShadowTextureReceiverMaterial("");
//m_pSceneMgr->setShadowTextureCasterMaterial("");

shadowCamera.setNull();

#ifdef USE_RTSHADER_SYSTEM
mShaderGenerator->removeSceneManager(m_pSceneMgr);
finalizeRTShaderSystem();
#endif

m_pRoot->destroySceneManager(m_pSceneMgr);

/* The ogre ray cast */
delete ogreRay;

if(m_pRoot != NULL){
//m_pRoot->removeFrameListener(snapshotFrameListener);
m_pRoot->shutdown();
delete m_pRoot;
m_pRoot = NULL;
}

/* Access to timer */
delete m_pTimer;

/* Access to log */
delete m_pLog;

#ifdef OGRE_STATIC_LIB
m_StaticPluginLoader.unload();
#endif
I ran a test case where I started Ogre, loaded a model, destroyed Ogre, navigated to another screen, started Ogre again, loaded the same model and then checked the profile. The attached image shows the results of the current memory footprint. It seems a number of textures are being created by loading images through the createEntity method when the model is loaded but are not cleaned up after ogre is destroyed. Can anyone tell me why this might be occurring? I am deleting the root and trying to clean up as much of the resources as possible but it seems these bits are being missed. Is there a method I have missed or something else I should be doing?

Thanks
You do not have the required permissions to view the files attached to this post.
chocoanzak
Kobold
Posts: 36
Joined: Wed Mar 28, 2012 2:00 pm

Re: Memory cleanup on iOS

Post by chocoanzak »

I continued investigating the issue and found some of the memory consumption was that the RTShader not being cleaned up. Once I forced a shutdown and cleanup of the RTShader I got some of the memory back although not all of the leak. Any advice on where else to look would be welcome
supadenz
Halfling
Posts: 41
Joined: Sat Feb 16, 2013 2:18 am
x 1

Re: Memory cleanup on iOS

Post by supadenz »

I had a similar problem a while back. What code exactly did you use to cleanup the RTShader?