A memory leak

Chris Jillings (chris@owl.phy.queensu.ca)
Fri, 8 May 1998 15:21:53 -0400 (EDT)


Hi,
I am running root v2_00_05 on Linux. I am compiling my code.
The following loop causes the image size to grow and grow until the
machine is swamped (up to 80 MBytes!). I can't see the leak. Help!

Chris

PS I did try to delete dir1 and dir2, which caused immediate core dump.
I have commented out those statments. I understand that
h20 = (TH1C*)dir2->Get(histName);
causes a histogram object to get created in memory, and I must delete it.
But why then should
delete dir1;
cause a core dump?

Thanks.

for( card=0 ; card<16 ; card++ ) {

printf("Working on crate %d, card %d.\n",crate,card);
for( channel=0 ; channel<32 ; channel++ ) {
sprintf(dirName1,"Crate %d",crate);
sprintf(dirName2,"Card %d",card);
sprintf(histName,"Cr %2d. Ca %2d. Ch %2d. Ped corrected, uncut IHL",
crate,card,channel);
fDAQ20->cd();
dir1 = (TDirectory*)fDAQ20->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h20 = (TH1C*)dir2->Get(histName);
// delete dir1;
// delete dir2;
fDAQ16->cd();
dir1 = (TDirectory*)fDAQ16->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h16 = (TH1C*)dir2->Get(histName);
fDAQ12->cd();
dir1 = (TDirectory*)fDAQ12->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h12 = (TH1C*)dir2->Get(histName);
fDAQ8->cd();
dir1 = (TDirectory*)fDAQ8->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h8 = (TH1C*)dir2->Get(histName);
fDAQ6->cd();
dir1 = (TDirectory*)fDAQ6->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h6 = (TH1C*)dir2->Get(histName);
fDAQ4->cd();
dir1 = (TDirectory*)fDAQ4->Get(dirName1);
dir1->cd();
dir2 = (TDirectory*)dir1->Get(dirName2);
dir2->cd();
h4 = (TH1C*)dir2->Get(histName);

//
// I ran the code with the following commented out and the image still
// grew very large.
//
// // Now have histograms. Fill array.
// hist[0] = h4;
// hist[1] = h6;
// hist[2] = h8;
// hist[3] = h12;
// hist[4] = h16;
// hist[5] = h20;
// clicker = new Clicks(hist,6,crate,card,channel,fout);
// clicker->AnalyzeEfficiency();
// clicker->Report();
// //if( channel==0 ) {
// // clicker->PlotChannel();
// //theApp.Run(kTRUE);
// // }
// clicker->~Clicks();

delete h4; delete h6; delete h8; delete h12; delete h16; delete h20;

}
}

=================================================================
= =
= Chris Jillings =
= Department of Physics phone/voice mail: (613) 545-6000x4805 =
= Queen's University fax: (613) 545-6813 =
= Kingston, Ontario email: chris@sno.phy.queensu.ca =
= Canada, K7L 3N6 web: http://sno.phy.queensu.ca =
= =
=================================================================