Jump to content
  • Advertisement
Sign in to follow this  

reported leaks caused by singletons?

This topic is 4720 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...

int PASCAL WinMain(...)
CVideo vga;

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();
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!