Re: TMapFile::Get

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Jul 12 1999 - 19:12:53 MEST


Hi Thomas,

   you need to delete the object returned by TMapFile::Get() because every
time you call Get() a new copy is returned. In principle I could re-use
the previously allocated space and would only have to call explicitely the
objects dtor to delete any internally allocated memory.

If you don't want to delete the previous object via the Get() call you should
keep track of all objects returned by Get() and delete them yourself at a
later and better time. You can easily do this by creating a TList and just
add the objects there. When done, call TList::Delete().


Cheers, Fons.



Thomas Eberl wrote:
> 
> Hi rooters,
> 
> I have a problem with the TMapFile class. In the source code for the Get
> method there is a comment saying that :
> 
>    // Return pointer to object retrieved from shared memory. The object
> must
>    // be deleted after use. If delObj is a pointer to a previously
> allocated
>    // object it will be deleted. Returns 0 in case object with the given
>    // name does not exist.
> 
> Why is it necessary to delete the object after use ?
> I observe a memory leakage if I do not delete the object. Why is this so
> ? To put the object as argument "delObject" does not help. My problem
> is, that I use more than one TTimer object in my code which use the
> objects in SM at different times, so that I get a synchronisation
> problem if I delete immediately the object that I have retrieved from
> Shared Memory.
> 
> --
> Thomas Eberl                       Phone: (+49 89) 289 1 2425
> Physik-Department E12, Technische Universitaet Muenchen
> James-Franck-Strasse *** 85748 Garching b. Muenchen
> Email: Thomas.Eberl@physik.tu-muenchen.de

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



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