Detecting Memory Leaks?

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Detecting Memory Leaks?

Post by SomeFusion »

Hi

what do you use to detect memory leaks? Just the internal Ogre leak detection? I'm having the problem the ogreleak.log is detecting loads of leaks (the file is usally around 8 MB after closing my programm), Most of them seem to be related to the ParticleManager. The file points me to ogreparticlesystem.cpp(424) Ogre::ParticleSystem::increasePool. But there are some others that don't have a description available. Are those caused by me or Ogre?


I have the problem in my application I can shoot rockets but whenever I shoot one, the performance drops down for about 20 FPS and I don't know where its caused. Is it possible those leaks cause the problem?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

no it's not leaks that make the slowdown.
Check here to prevent slowdown on rocket launch: http://www.ogre3d.org/phpBB2/viewtopic. ... 4762#54762

Leaks are correclty reported by ogreleaks.
Perhaps this solution will also resolve your leaks, as you'll get a centralized pool of particle to release at the end of the program
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

The Problem is not the ParticleSystem. I don't create something new at Runtime, only at loadtime. The only thing I do after a Rocket is fired is check whether the rocket is active or not and translate its node in the direction its heading. Its nothing that would slow down the game so much. I have no collision detection yet. If you want to try here's a precompiled version:

http://www.malwasandres.de/spacecleaner_0.02.rar


I'll try to setup a berlios.de account so I can use their svn server to store the source.
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

1- OgreLeaks are surely exact... You do have lots of memory leaks.
Do you release any pointer ? for shaderptr you need to set ptr.setNull () before ending appand and delete any newed object.


2- The way you manage particle system for engine boost seems not good at all... There nearly 100 particle on screen but ogreleaks says that you "increasePool" 100.000 times !!??? that means millions of particles allocated.... So there's a problem here.

3- Is the fps loss the same when you launch sphere or box instead of ninjas ?
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

tuan kuranes wrote:1- OgreLeaks are surely exact... You do have lots of memory leaks.
Do you release any pointer ? for shaderptr you need to set ptr.setNull () before ending appand and delete any newed object.
Do you mean sharedptr? I never used a sharedptr.
tuan kuranes wrote: 2- The way you manage particle system for engine boost seems not good at all... There nearly 100 particle on screen but ogreleaks says that you "increasePool" 100.000 times !!??? that means millions of particles allocated.... So there's a problem here.
I don't know why there are so many calls to increasePool. I create the particle system at startup and incrase the particle count or decrease it depending on the engine. This is the code:

Code: Select all

		if (!mEngineParticlesSet)
		{
			std::cout << "high" << std::endl;
			mEngineParticlesSet = true;
			mEngineEmitter->setEmissionRate(150);
			mEngineEmitter->setMaxTimeToLive(0.9f);
			mEngineEmitter->setMinTimeToLive(0.7f);
		}
		if (mEngineParticlesSet)
		{
			std::cout << "low" << std::endl;
			mEngineParticlesSet = false;
			mEngineEmitter->setEmissionRate(20);
			mEngineEmitter->setMaxTimeToLive(0.5f);
			mEngineEmitter->setMinTimeToLive(0.3f);
		}

That means the emission rate is set to 150 the the engine is switched on and set to 20 when the engine is off. This only happens once when the user releases the key and when the user presses the key.
tuan kuranes wrote: 3- Is the fps loss the same when you launch sphere or box instead of ninjas ?
Hmm not as much as they do with ninjas. Is a fps loss for 10 normal for just one additional cube wich only translates in one direction?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

There's something wrong in your source... that doesn't raise on opengl,
but D3d9 just segfault (but I cannot see the exception message, too long for the text box.)
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

Thats the D3D9 Vertex Buffer bug disussed here:
http://www.ogre3d.org/phpBB2/viewtopic. ... tex+buffer

I'll take a newer CVS snapshot where this bug is fixed.

Btw, Sinbad was kind enough to change my name to something less stupid. :)
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

tweaked your particle file to set a quota 10 and got a much readeable leaks file. Seems that you allocate 5 "players", each time creating a new particle system, with your 10.000 quota that gives the 50.000 increase pool.

After that, without source, hard to help much more.
Perhaps you're not exiting the App the right way, thus preventing Ogre to relase his internals objects.
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

I'll upload the source tomorrow to my webspace. I already tried to setup a berlios project so I can use their svn server but they declined my project because of a to short description.
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

Ok here is the source.

http://www.malwasandres.de/spacecleaner0.02source.rar

The Quota really was to high. But there are still to many memory leaks from the ParticleSystem. How do I shutdown the system correctly? At the moment i just return false in the frameStarted method.
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

You should delete what you're allocating (and only that):

- in ~GameApp you should delete player asteroid...

- you should use mSmokeSystem->removeEmitter ParticleSystemManager::getSingleton().destroySystem
when deleting objects that had created particle system

- delete[] &mRockets and delete[] &mStage2 is wrong C++ when you do no allocate mStage2 and mRockets yourself.

- delete obj; objList.remove(obj); is in wrong order...


It's not meant to be rude, but you have to re-check some C++ basis (specially memory management), otherwise you'll have hard time.
I can assure you that it will be faster to check basis and then try to program, than try and debug without understanding what's happening.

For instance, read some on-line books (you'll learn some optimizations too):
http://www.rz.rwth-aachen.de/computing/ ... 1.18-1.pdf

Then some other readings here :
http://www.ogre3d.org/phpBB2/viewtopic. ... hlight=stl
User avatar
SomeFusion
Gremlin
Posts: 191
Joined: Sun Dec 01, 2002 12:38 am
x 3

Post by SomeFusion »

Thank you for your answers! I'm sorry for not responding earlier but the weather was to good for not going snowboarding :). I've been programming in C# the last few month so I have a bit of a problem with the delete stuff.

I'll read through your links.
Post Reply