Re: A memory leak

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri May 08 1998 - 22:25:25 MEST


Chris,
To answer your question, I need a bit more info with a real macro
not just extracts of your code.
You can heavily simplify the code below (see TDirectory::cd)
You should not Get(directory) in memory. Just cd to this directory.
Please reply to me directly, not to this list.

Rene Brun

Chris Jillings wrote:
> 
> 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        =
> =                                                               =
> =================================================================



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:32 MET