understanding destructors


i am having poblems when i close an app i am working on. The app closes down but the terminal stays open, if I close the terminal i get a windows alert saying:

“the instruction at “0x00816a25” referenced memory at “0x00ef2734”. The memory could not be “read”. Click OK to terminate the program.”

I click OK and the terminal says :

“Process returned -1073741819 (0xC0000005) execution time : 47.277 s
Press any key to continue.”

then I press any key and it finally closes.

I am using several things in this app including some addOns. OpenCV, XML and OSC. I have three vectors containing ofImage, ofVideoPlayer and ofVideoGrabber.

I bet I am not destroying something that should be destroyed. But i dont know where to destroy things. i declared ~testApp() and put some code there but this does not get called.

is there any OF online docs about this? thanks!


This might be an issue with FreeImage I think I’ve seen before… if you hit the escape key to close OF windows in Windows, it’s safer than hitting the “X” (close) button on the window. See if that helps?

you are right!, yes it does work. i tested few OF examples and many have the same problem. So it is not me doing something wrong.

anyway… i am still intrigued by where to place code that will run when the app is quiting. any hints? thanks!!

testApp has an exit() function that you can use…check out the header file for the ofBaseApp class. It gets called when the app exits.

Otherwise you can use the testApp destructor which does pretty much the same thing.

Just write in the testApp.cpp

 // clean up stuff here  

and then in the .h file:


i just found that ~testApp() was working since the begining. i got confused because i have been working on windows the last days and when i closed the app from the X button the destructor was not being called. But i just noticed that if i press ESC the destructor does get called. So everything is clear now.