Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMatias Goldberg

Posted 14 November 2012 - 10:54 AM

No one really saw it? Really???

There's a lot that goes on after leaving main(); hence why it's telling you there are leaks.
Try using atexit.

Personally, I prefer to create a static object, ensure it's the first one to get created, and then let the C++ compiler clean up last:

[source lang="cpp"]class MeFirst{ MeFirst() {} ~MeFirst() { /* -- call CRT debug dump here -- */ } static MeFirst& getSingleton() { static MeFirst instance; return instance; }}int main(){ //Calling first may ensure the static initialization goes first. volatile MeFirst &doThisFirst = MeFirst::getSingleton(); return 0;}[/source]

It's out of my head, and beware I may be missing a case where another static variable gets initialized before this one, hence you may still get leaks (before it will be destroyed after CRT dump). Anyway, try different approaches, google a little, experiment, and find out how to make the CRT Dump get truly called last.
wxWidgets manages to do it correctly, you may want to take a look there.

Cheers
Dark Sylinc

Edit: Oh, and Singleton is an evil pattern. Don't use it. This is an exception because you're not actually using it.

#2Matias Goldberg

Posted 14 November 2012 - 10:54 AM

No one really saw it? Really???

There's a lot that goes on after leaving main(); hence why it's telling you there are leaks.
Try using atexit.

Personally, I prefer to create a static object, ensure it's the first one to get created, and then let the C++ compiler clean up last:

[source lang="cpp"]class MeFirst{ MeFirst() {} ~MeFirst() { /* -- call CRT debug dump here -- */ } static MeFirst& getSingleton() { static MeFirst instance; return instance; }}int main(){ //Calling first may ensure the static initialization goes first. volatile MeFirst &doThisFirst = MeFirst::getSingleton(); return 0;}[/source]

It's out of my head, and beware I may be missing a case where another static variable gets initialized before this one, hence you may still get leaks (before it will be destroyed after CRT dump). Anyway, try different approaches, google a little, experiment, and find out how to make the CRT Dump get truly called last.
wxWidgets manages to do it correctly, you may want to take a look there.

Cheers
Dark Sylinc

Edit: Oh, and Singleton is an evil pattern. Don't use it. This is an exception because you're not actually using it.

#1Matias Goldberg

Posted 14 November 2012 - 10:53 AM

No one really saw it? Really???

There's a lot that goes on after leaving main(); hence why it's telling you there are leaks.
Try using atexit.

Personally, I prefer to create a static object, ensure it's the first one to get created, and then let the C++ compiler clean up last:

[source lang="cpp"]class MeFirst{ MeFirst() {} ~MeFirst() { /* -- call CRT debug dump here -- */ } static MeFirst& getSingleton() { static MeFirst instance; return instance; }}int main(){ //Calling first may ensure the static initialization goes first. volatile MeFirst &doThisFirst = MeFirst::getSingleton(); return 0;}[/source]

It's out of my head, and beware I may be missing a case where another static variable gets initialized before this one, hence you may still get leaks (before it will be destroyed after CRT dump). Anyway, try different approaches, google a little, experiment, and find out how to make the CRT Dump get truly called last.
wxWidgets manages to do it correctly, you may want to take a look there.

Cheers
Dark Sylinc

PARTNERS