The problem of memory leak

Problems building or running the engine, queries about how to use features etc.
Post Reply
OliverWPZ
Halfling
Posts: 53
Joined: Sun Feb 20, 2005 10:55 am

The problem of memory leak

Post by OliverWPZ »

I want to change the entity of a node when I push "x".There are the codes.It works .But there are some problem.When I pushed "x" several times,the memory increased 4K.Who tell me why? Thanks.

if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0)
{
SceneNode* mRoleNode = mSceneMgr->getSceneNode( "roleNode" );
if(mRoleNode){
String meshNames[]={"ZFGirl.mesh","robot.mesh"};
String entAnimations[]={"walk","Walk"};
//MovableObject* thisObject=mRoleNode->detachObject("roleEnt");
// delete thisObject;
mSceneMgr->removeEntity("roleEnt");

roleNodeIndex=roleNodeIndex ? 0:1;
Entity* roleEnt = mSceneMgr->createEntity( "roleEnt", meshNames[roleNodeIndex] );
roleEnt->setCastShadows( true );
mRoleNode->attachObject( roleEnt );
mRoleAnimState->setEnabled(false);
mRoleAnimState = roleEnt->getAnimationState(entAnimations[roleNodeIndex]);
mRoleAnimState->setEnabled(true);
mTimeUntilNextToggle = 0.5;
mWindow->setDebugText("meshNames["+StringConverter::toString(roleNodeIndex)+"]:"+meshNames[roleNodeIndex]);
}
If you love something...set it free...if back: it`s yours...or:it`s never
User avatar
Lucky_Luciano
Greenskin
Posts: 136
Joined: Mon Feb 14, 2005 9:25 pm
Location: Belgium

Post by Lucky_Luciano »

I'm new to Ogre but I think you should explicitely destroy a node instead of just removing the entity.

If your node is called "MyNode", use this:

Code: Select all

mSceneManager->getRootSceneNode()->removeAndDestroyChild("MyNode");
and add a new node containing the new entity.

Perhaps that helps?
Post Reply