Re: Pb. when delete pointer to TTree

Rene Brun (Rene.Brun@cern.ch)
Sat, 08 Nov 1997 16:42:32 +0100


Laurent Aphecetche wrote:

> Hi,
>
> Owing the following "program" :
>
> file = new TFile...
> tree = new TTree("EM","EM particles",1000000) ;
> gEvent = new RBEvent ;
> b = tree->Branch("event","RBEvent",&gEvent,20000,1) ;
>
> ...
>
> tree->Write() ;
> file->Close() ;
> delete file ;
> delete b ;
> delete tree ;
> delete gEvent ;
>
> I got a SEGV on the delete b.
> Is there a special way (or order) to delete pointers on branches or
> trees.

When you close a file, histograms and Trees created on this file
disappear from memory as well.
You do not need to delete branchs and trees.
Remove the two statements
delete b;
delete tree;
otherwise your program will crash because you attempt to delete
an object twice.

Rene Brun