A simple question regarding memory (de)allocation

Hello,

I’m running a very simple ROOT macro from the interpreter (.L macro.C, macro()). My code looks like that:

void macro()
{
TFile *f[100];

f[0] = new TFile("file0.root");
f[1] = new TFile("file1.root");
....
f[99] = new TFile("file99.root");
....
(create one empty histo, and add one histo from each file to it)
....

for(unsigned a=100; a>0; --a)
 {
   delete f[a-1];
 }

delete[] f;
}

Clearly opening 100 30MB files takes up a lot of memory, and indeed ROOT memory usage gros to 2GB or so, but it doesn’t reduce even though I use some delete statements. I can run the macro two or three times, but then ROOT will run out of memory and exit.
The question is, why is that so? The delete statements should free up memory, shouldn’t they?
I’m using ROOT v4.04.02b.

Thanks,

T.

move to a more recent version, eg 5.18

Rene

Hi,

and even then e.g. Linux will only free the memory once the last allocation is deleted. So inverting the loop would help. Even better: you should move the “new” into the loop: [code]void macro()
{
TFile *f0 = new TFile(“file0.root”);

(create one empty histo, and add one histo from each file to it)

for(unsigned a=100; a>0; --a)
{
TFile *fx = new TFile(Form(“file%d.root”, a);

delete fx;
}
}[/code]
Btw, your for loop assumes you have 101 files (100 to 1, plus the f[0] or f0 in my code).

Cheers, Axel.