GUI tutorials and memory management


I have a gui that I built on the guitest.C tutorial and then extended/modified. I decided to try and be responsible and do some memory management and make sure everything is being deleted properly. I will just reference the guitest.C tutorial since my code is built on it. As far as I can tell, the destructor for TestMainFrame is never called. All the other classes (TestDiaglog, TestSliders, etc.) have a CloseWindow() method which calls ‘delete this’ for the class and therefore calls their respective destructors. The MainFrame, under TestMainFrame, only calls gApplication->Terminate() under its CloseWindow() method.

I added in a print statement to the TestMainFrame::~TestMainFrame and saw that it is not called. So unless gApplication->Terminate() is doing some other cleanup, it seems that things are being left allocated and causing memory leaks. Should the CloseWindow be changed?:




delete this;

Where now the destructor will be called. Also, is there supposed to be a behavior difference between

delete fMain;



Thank you,

_ROOT Version: 6.16.0
_Platform: Mac OSX 10.14.6
Compiler: Not Provided

You’re right, the deletion is missing (might still be called via gApplication->Terminate() though). And indeed this code should work:

Another solution would be to make TestMainFrame inheriting from TGMainFrame, instead of having it as class member…
And fMain->DeleteWindow(); makes proper cleanup before deleting the class itself, but both should work (might be tricky with the Window Manager)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.