Here’s the memory leak detection system I would like to use with Visual Studio:
// ... other OF windows setup code here ...
// Game is type: class Game : public ofBaseApp
gGame = new Game();
// *** Never reaches this point in the code on a normal ESC key press exit from app
_CrtDumpMemoryLeaks(); // VS leaked reporting method
Due to the OpenFrameworks event handling, the process exits using a std::exit(0) and ofRunApp never returns for gGame to be explicitly deleted and thus _CrtDumpMemoryLeaks() is also never called.
So what I’m asking (though I’m open to other workarounds) is: How do I get ofRunApp() to return upon process shutdown so it exits normally through the end of main()?
ofRunApp should be returning. What version of openFrameworks are you using?
It returns the exit code so you can use:
you can also try to explicitly create an ofMainLoop as in:
auto app = make_shared<ofApp>();
auto window = ofCreateWindow(settings);
but it shouldn’t be necesary
Hi Arturo! Thank you for your reply. Much appreciated. I’m using 0.9.8.
Here is the method that is eventually terminating my process when ESC is pressed. I’m not doing any special handling of ESC. It’s the default OF handling of it that calls the std::exit(0);
std::exit(0); // <<<<<<<<<<<<<<<<<<<<<<<<<< exits here
My issue is that I need _CrtDumpMemoryLeaks() to be called after all dynamically allocated objects have been freed or in my case, the last line of main() before the return 0. As shown in my example code in my first post.
I guess I can do my own handling of the ESC key press and shut it down manually. Maybe that’s the best work around.
mmh yeah if you are using the glut window then the loop never finishes but that’s window is deprecated. Are you using it for some specific reason? otherwise take a look at any of the examples to see how to change it with a glfw one or just use the code i posted above
I switched over the windows creation method with th initialization using ofGLFWWindowSettings and it now ofRunApp returns upon my call of ofExit()!
Thank you! Problem solved!