[Insight-developers] List of smart pointers

Blezek, Daniel J (Research) blezek@crd.ge.com
Fri, 1 Nov 2002 09:09:01 -0500


Exactly right, but I was using LightObject as a superclass of an internal class that did not use the
New() construct.  LightObject depends on the correct behavior of New, if you use it naively, as I
did, the memory is never freed.

-dan

--
Daniel Blezek, Ph.D.
blezek@crd.ge.com
Visualization and Computer Vision Lab, Imaging Technologies
GE Global Research Center


> -----Original Message-----
> From: Brad King [mailto:brad.king@kitware.com]
> Sent: Friday, November 01, 2002 8:58 AM
> To: Insight Developers
> Subject: RE: [Insight-developers] List of smart pointers
> 
> 
> On Fri, 1 Nov 2002, Blezek, Daniel J (Research) wrote:
> > I noticed that itkLightObject is created with a reference 
> count of 1.
> > This was the cause of one of my memory leaks, since 
> LightObject never
> > called delete, i.e. reference count was never below 1.  You 
> could simply
> > assign the object to your list of smart pointers, the Unregister it
> > once, to correctly set the reference count.
> 
> The constructor does initialize it to 1, but then the New() 
> method assigns
> it to a smart pointer and calls UnRegister before returning 
> it.  This is a
> change that was made (by Jim, I think) to prevent problems 
> with changes in
> the reference count at construction time deleting the object during
> construction.
> 
> Once one assigns the result of New() to a smart pointer, the 
> object has
> reference count 1, and is owned only by the smart pointer.  
> When the sp
> destructs, the object should be freed.
> 
> -Brad
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>