Re: [ROOT] TPad memory problems in GUI

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Sep 18 2001 - 15:42:35 MEST


Hi Robert,

If you have a TPad *mypad object in a canvas, you cannot do:
  if (mypad::IsRetained()) after having deleted the canvas. At this point, mypad
will point to a deleted object.

You can test if a pad (eg with name "mypad") is inside a canvas with
  if (canvas->GetPrimitive("mypad")) // then the pad exists
or
  if (canvas->GetListOfPrimitives()->FindObject("mypad"))

You can test if a canvas my name "mycanvas" exists with
  if (gROOT->GetListOfCanvases()->FindObject("mycanvas")) //canvas exists.

Rene Brun

Robert Michaels wrote:
> 
> I have two systems, both running root 3.01-06 (compiled on each system).
> 
> System I:  RedHat 6.2 kernel  2.2.19-6.2.7
> System II:  RedHat 7.1  kernel 2.4.8
> 
> I have a complicated GUI.  I suppose I should show a simple example of
> my problem, but let's see if I can get a hint from this description.
> 
> My GUI makes creates a "new TCanvas" in which it makes other new TPad's
> and then uses TH1F::DrawCopy to draw histograms so that the TPad's own
> the THistPainter and whatever else is created by DrawCopy.
> 
> At first I observed memory leaks, but on "System I" this was solved
> by deleting the TPad's and TCanvas's I "new'd" before trying to "new"
> again.   Also by usinig TH1F::DrawCopy.  The method gObjectTable::Print()
> and "top" verified a stable total heap size.
> 
> Then I had a problem when deletion occurred by pressing "X" in the
> top right side of the window to delete the TCanvas "by hand" (or if one
> used the TCanvas's File->Delete in top left of canvas to delete).
> I tried to use the TPad::IsRetained()  method to see if a TPad had
> been deleted.  If it IsRetained was kFALSE, I didn't try to delete again,
> and the code was stable on System I.   Perhaps this was an accident
> since the IsRetained method belonged to a TPad that "X" presumably
> deleted.  Nevertheless it seemed to work.  However, on System II, I get
> segmentation faults, and IsRetained always returns kTRUE.
> 
> My question is :  How can I tell if a TPad object was deleted ?
> (This is probably very basic C++ ...)
> 
> Thanks !
> ------------------------------------------------------
> Robert W. Michaels
> www.jlab.org/~rom
> phone (757) 269 7410   pager (757) 881 7897
> Thomas Jefferson National Accelerator Facility
> 12000 Jefferson Ave, Newport News, VA 23606 USA



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:00 MET