Re: Regard to the memory leak in BlastLib2

From: zhangchi (zhangchi@general.lns.mit.edu)
Date: Wed Sep 18 2002 - 11:35:38 EDT


Hi Adam,

This is a nice trick. On the other hand, will root do something similar
automatically? for instance when we say .q, will it go over all the names
in the TDirectory and delete things accordingly?

Chi

On Wed, 18 Sep 2002, Adam DeGrush wrote:

> Hello All,
>
> There is a way that ROOT facilitates keeping track of objects created on the
> heap using "new" . One can create a TList container and then add every object
> to the container as its created. So for example:
>
>
> //Create a TList
> TList *fTrashCan = new TList;
>
> //An ordinary class
> myClass *A = new myClass;
> anotherClass *B = new anotherClass;
> //Add them to the container
> fTrashCan->Add(A);
> fTrashCan->Add(B);
>
> //When you are done with the object, ROOT will free the memory taken by A and B
> in one fatal swoop
> fTrashCan->Delete();
>
> //Then free up memory by fTrashCan
> delete fTrashCan;
>
>
> This may help someone
>
> Cheers,
> Adam
>



This archive was generated by hypermail 2.1.2 : Mon Feb 24 2014 - 14:07:28 EST