Hi, ROOTers
I am working on creation of GUI with ROOT TGObjects (I mean TGFrame and so on).
And I found the most difficult concept (so far) is to How and when to delete TGObjects.
It matters because almost every widget is supposed to be created in heap with new operator.
Cleanup() and SetCleanup()
I see there is a method called Cleanup in TGCompositeFrame. And it is written in its documentation:
Cleanup and delete all objects contained in this composite frame.
This will delete all objects added via AddFrame(). CAUTION: all objects (frames and layout hints) must be unique, i.e. cannot be shared.
OK. So considering the following code
//Somewhere in the code (probably in ctor)
TGMainFrame *fMain;
fMain = new TGMainFrame( ... );
...
//Somewhere else in the code
TGCompositeFrame *subFrame = new TGCompositeFrame( fMain, ... );
TGLayoutHints *subLayout = new TGLayoutHints( ... );
fMain->AddFrame( subFrame, subLayout );
So questions here are :
- Should I use the
Cleanup()method offMainin its destructor? - If I did what pointers would be freed:
subFrameandsubLayout? - And the most important question: What would be with those
TGObjects which added viasubFrame’sAddFramemethod if I did ? - One more question is what if I used the above
subLayoutto manage the placement of otherTGFrame? I.e. somewhere in the codefMain->AddFrame( otherSubFrame, subLayout )and then usedfMain->Cleanup? Is it double deletion or smth?
I saw in tutorials/gui/guitest.C most of Test-classes contain the following line:
fMain->SetCleanup( kDeepCleanup );
But non of them calls the Cleanup() method in its dtor. They are rather deleted either via the DeleteWindow() method or with delete this line.
So I confused a little bit.
ROOT Version: 6.16/00
Platform: Linux, Ubuntu 16.04
Compiler: gcc 5.4.0