When to use TGCompositeFrame::Cleanup method?

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 of fMain in its destructor?
  • If I did what pointers would be freed: subFrame and subLayout ?
  • And the most important question: What would be with those TGObjects which added via subFrame’s AddFrame method if I did ?
  • One more question is what if I used the above subLayout to 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


not if you enabled the automatic cleanup with fMain->SetCleanup()

Yes, they would be deleted

Objects should be deleted anyway. The difference is who controls the deletion: you or the GUI manager.

Yes, if you use GUI sub-elements in different composite frames, you have to control the way those sub-elements are deleted.

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