Re: deleting hist from memory

From: Axel Naumann <axel_at_fnal.gov>
Date: Thu, 17 Mar 2005 11:40:02 -0600


Hi Boris,
use "delete obj". gDirectory could also be the current file, so explicitly using gROOT is safer. And this code snippet should be a bit faster:

> TIter nextkey(gROOT->GetListOfKeys());
> TKey *key;
> while (key = (TKey*)nextkey())
> if (key->Class()
> && key->Class()->InheritsFrom( TH1::Class() )
> delete key->ReadObj();

Note how it compares pointers instead of strings, only tests for TH1 (TH2 derives from TH1, so whatever is satisfied by InheritsFrom(TH2::Class()) will also be satisfied by InheritsFrom(TH1::Class())), and reads the key only if the class matches (which is not really relevant for in memory objects).

Axel.

Boris Skorodumov wrote:
> dear rooters,
>
> i have simple question:
>
> suppose i created in memory several 1d and 2d histogram. {via TH1D *h =
> new TH1D("h",..... ) ....}
> after that im filling them with some criteria.
> Finally i am deleting them from memory. Now i whould like to
> run script again to do the same procedure. Just to be save, i am trying
> in script delete all of the histograms in memory via next script:
>
> TIter nextkey(gDirectory->GetListOfKeys());
> TKey *key;
>
> while (key = (TKey*)nextkey()) {
>
> TObject *obj = key->ReadObj();
> if ( obj->IsA()->InheritsFrom( "TH2" ) ||
> obj->IsA()->InheritsFrom( "TH1" ))
> obj->Delete();
> }
>
> but still i see all OBJ in memory. is it something wrong ?
>
>
> thank you,
>
> boris.
>
Received on Thu Mar 17 2005 - 18:47:03 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:06 MET