Sign in to follow this  

reported leaks caused by singletons?

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm using crazy eddie's GUI system for my DirectX9 app. The thing is I get reports of memory leaks. I've tried breaking on the leak IDs but the I never get a break. Can these leaks be caused by the fact that CEGUI uses singletons and that they are actually unallocated after my _CrtDumpMemoryLeaks() call in the main program? If so, any ideas of how to get around it? cos it's pretty annoying and makes finding actual leaks very hard.

Share this post


Link to post
Share on other sites
Hi DarkZoulz!

Absolutely! "Static" objects that are instantiated pre-main in DLLs and even in EXEs can show up as memory leaks. This happens particularly often when those objects allocate their own objects on the heap because usually memory leak detectors are shut down before these objects have freed their memory.

Pretty much the only way to find these nasty leaks is to use a memory leak detection program that opens the target application up as a debugee, like BoundsChecker, or you can write something similar yourself if you're familiar with writing debuggers. :D

- John




Share this post


Link to post
Share on other sites
I had the same problem!

I encapsulated CVideo : public CSingleton<CVideo>, CSingleton<Input>, CSingleton<Sound> etc...
example:

int PASCAL WinMain(...)
{
CVideo vga;
vga.init(640,480);
vga.done();
_CrtDumpMemoryLeaks();
}

At point of calling _CrtDumpMemoryLeaks() VGA is not destroyed completly yet but it WILL BE after WinMain() finishes (that is after _CrtDumpMemoryLeaks()).

The soulution?

CVideo* pVga = new CVideo();
pVga->init(640,480);
pVga->done();
delete pVga; //now it is deleted - if your singleton allows that?!
_CrtDumpMemoryLeaks(); -- it works

There is somekind of preset where _CrtDumpMemoryLeaks() will be called automaticaly on program exit, so you do not need to explicitly call it. But still it hapens before WinMain() exits (the last line) so in the first case it would still be wrong.

Share this post


Link to post
Share on other sites

This topic is 4377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this