Re: [ROOT] memory leak in canvas creation / deletion ?

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Aug 23 2004 - 11:41:06 MEST


Hi Eric,

   we've fixed two smaller memory leaks that became apparent during the
investigation. However, the main "leak" is not really a leak but a
feature. If you create a canvas on X11 this generates a number of X11
events (idem for the other graphics backends) that need to be handled.
If these events are not handled they stack up in the X11 client queue
which is part of the process. On X11 this is about 6kb per canvas. If
you change you macro as follows:

macro1 :
{
  TCanvas* c;
  int i;
  for (i=0; i< 10000; i++) {
    c = new TCanvas();
    gSystem->ProcessEvents();
    delete c;
 }
 }

then the memory leak is gone.


Cheers, Fons.



On Mon, 2004-08-23 at 10:52, Rene Brun wrote:
> Hi Eric,
> 
> Thanks for reporting the memory leak when creating/deleting canvases. We will
> fix this problem.
> 
> Concerning your macro2, this is the expected behaviour. There is no leak. This
> is simply the C++ memory fragmentation problem where the compiler tries to
> optimize a large buffer of small objects being created/deleted.
> 
> Rene Brun
> 
> eric.anciant@noos.fr wrote:
> > 
> > Hello rooters,
> > 
> > I have in fact two questions one leading to the second one :
> > 
> > Question 1 :
> > 
> > Using ROOT 4.00/08 with GDK on WIN2000
> > 
> >   *   Version   4.00/08       9 July 2004   *
> > Compiled for win32.
> > CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
> > 
> > I suspect a weird memory leak when drawing canvas : I have an
> > application that display a few canvas (in fact 3) in which I draw and
> > updates graphs and histograms over hours, meanwhile the memory usage of
> > the application grows slowly but constantly ( from about 20 M to 100's
> > of Meg, eventually crashing the system). I am quite confident with the
> > rest of the code, because if I remove the drawing of the canvas (keeping
> > creation/deletion of histograms and graphs), the leak doesn't appear,
> > and because of the funniest part : If I iconify the 3 canvases
> > (graphically using the mouse) the memory usage of the application
> > suddently drops to very low (and to what I would expect the application
> > memory usage to be; a few megs ), and then starts again to grow ....
> > until I de-iconify and re-iconify again the canvases...
> > It looks to me more like a GDK / microsoft-windows low level interaction
> > than a root problem, did somebody have seen something equivalent ?
> > 
> > Question 2 :
> > 
> > I therefore tried a few things at home on Linux box; namely :
> > 
> > macro1 :
> > {
> > TCanvas* c;
> > int i;
> > for (i=0; i< 10000; i++) {
> >    c = new TCanvas();
> >    delete c;
> > }
> > }
> > 
> > macro2 :
> > {
> > TH2D* h;
> > int j;
> > for (j=0; j<10000; j++ ) {
> >    h = new TH2D("h","h",1000,0,1,1000,0,1);
> >    delete h;
> > }
> > }
> > 
> > macro1 shows a memory usage of root.exe that grows constantly,
> > macro2 shows a (though oscillating ..) steady memory usage.
> > 
> > Is this the expected behaviour ?
> > 
> > eric
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://www.rademakers.org/fons/      Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET