Where to delete class objects instantiated with the new operator in ofApp.cpp?


If I instantiate class objects inside ofApp.cpp, using the new operator - which allocates them in heap memory - , where do I need to delete them, if they remain valid until the application is closed?

Is there for instance something like an ofApp::exit() method that executes code right before quitting the application?
Or should I declare and define a destructor for the ofApp class, and if so, does it take care of the cleanup at the end, if I put delete myObject inside its definition?

I’m pretty new to C++! Any help is appreciated. :slight_smile:


Anybody? *bump

there is an exit function you can override.

should be also fine to add a destructor. i am not an expert c++ programmer, but i always try to avoid pointers. if i have to, then i try to use smart pointers. there is a chapter in the ofBook about smart pointers.
hope that helps

1 Like