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
It matters because almost every widget is supposed to be created in heap with
Cleanup() and SetCleanup()
I see there is a method called
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
fMainin its destructor?
- If I did what pointers would be freed:
- And the most important question: What would be with those
TGObjects which added via
AddFramemethod if I did ?
- One more question is what if I used the above
subLayoutto manage the placement of other
TGFrame? I.e. somewhere in the code
fMain->AddFrame( otherSubFrame, subLayout )and then used
fMain->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