[ROOT] Memory leakage

From: Zohrabyan Hamlet (zohrab@mail.desy.de)
Date: Sat Mar 20 2004 - 11:46:27 MET


Hallow ROOTers.

My working environment is:
Linux 2.4.25; ROOT 3.04/02; gcc 2.95.2

I am writing for H1-Collaboration a ToFMonitor program.
Recently I find very amusing (I were working  on it 2 weeks)
,unexpected,dangerous Memory Leakage.

Below is the simplified version of my program:
//----------------
#include <TROOT.h>
#include <TApplication.h>
#include <TRandom.h>
#include <TCanvas.h>
#include <TThread.h>
#include <TH1.h>

TCanvas *c1;
TCanvas *ftempo;
TH1F *h;
float x0,x1;

void simple()
{  c1 = new TCanvas("c1","Main Canvas", -400,400);
   c1->Draw();
   h = new TH1F("h1","h1",500,-50.0,200.0);
   c1->cd();   h->Draw();
//     h->SetFillColor(4);
//     h->SetLineColor(4);
}

void *fillhist(void *ptr)
{
  while(1)
  { gRandom->Rannor(x0,x1);  x0=x0*5+25;   x1=x1*10+50;
    h->Fill(x0);   h->Fill(x1);
    if(ftempo) {
      ftempo->Modified(); ftempo->Update();
    } else  ftempo  =(TCanvas*)gROOT->GetListOfCanvases()->FindObject("c1");
  }
}

TROOT root("GUI", "GUI test environement");
int main(int argc, char **argv)
{
   TApplication theApp("App", &argc, argv);
   if (gROOT->IsBatch()) {
     fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]);  return 1;
   }
   simple();
   TThread::EPriority pri;  TThread *th1;
   th1 = new TThread("th1", fillhist, (void*)0,  pri = (TThread::EPriority)1);
   th1->Run();
   theApp.Run();
   return 0;
}
//--------------------

I hope the code is very transparent so I don't explain it.
Compile it and run.Checking the program memory size you will see
that it is constant!!
Now remove one or both comments in lines
//     h->SetFillColor(4);
//     h->SetLineColor(4);
 recompile the program and run it again.
You'll see permanent increasing of program memory size!
Running for few hours it will cause the computer crash!
So my question is: How can it happen?What is wrong?
It is very important to understand
is it my code wrong or it connected with Root himself?


Thanks in advance,
   Hamlet Z.



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