[Insight-developers] destructor/smart pointer clean up
causin g crashes?
Bill Hoffman
bill.hoffman@kitware.com
Wed, 03 Oct 2001 16:14:00 -0400
We could do this, make Delete a static on LightObject, like so:
static itk::LightObject::Delete(itk::LightObject*)
{
if(obj)
obj->PrivateUnregister();
}
We would make Delete, Unregistor, and Registor private, and users
would have to pass the object to a static function to use them.
This would keep the smart pointers from calling these functions.
-Bill
At 03:47 PM 10/3/2001 -0400, Miller, James V (CRD) wrote:
>I fixed the problem I was having, I had code in this test like
>
> itk::XMLFileOutputWindow::Pointer logger = itk::XMLFileOutputWindow::New();
> logger->SetInstance(logger);
> logger->Delete();
>
>I was calling logger->Delete() to reduce the number of references to the
>output window since the output window class keeps a static handle to the
>output window.
>
>When the code is like the above, my program crashes on exit. It looks
>as though the logger is getting deleted twice on output. Once for
>when the logger variable goes out of scope and once when the static
>handle to logger gets deleted. This is one too many times.
>
>When I remove the logger->Delete() line, the program exits without error
>and Purify reports no leaks.
>
>Calling Delete() on my smartpointer, just propagated the Delete() call
>to the underlying object. The smartpointer itself did not release zero
>out its pointer. So when the smart pointer went out of scope, it tried
>to delete its reference again.
>
>Can we keep people from calling Delete() on a smart pointer (perhaps by making it
>protected)?
>
>
>
>-----Original Message-----
>From: Miller, James V (CRD)
>Sent: Wednesday, October 03, 2001 2:05 PM
>To: 'Bill Hoffman'; Wilson M Chang;
>insight-developers@public.kitware.com
>Subject: RE: [Insight-developers] destructor/smart pointer clean up
>causin g crashes?
>
>
>We are having some other problems with crashes on exit.
>
>The Testing/Code/BasicFilters/itkStreamingImageFilterTest2 is
>crashing on exit. This particular test using a subclass of the
>FileOutputWindow. Walking through the debugger, an exception
>is thrown when the smart pointer to the "static instance" of the
>output window is destroyed.
>
>
>-----Original Message-----
>From: Bill Hoffman [mailto:bill.hoffman@kitware.com]
>Sent: Wednesday, October 03, 2001 1:02 PM
>To: Wilson M Chang; insight-developers@public.kitware.com
>Subject: Re: [Insight-developers] destructor/smart pointer clean up
>causing crashes?
>
>
>I would have to see the code to tell.
>
>
>-Bill
>
>
>At 12:30 PM 10/3/2001 -0400, Wilson M Chang wrote:
>>I was writing a file reader following very closely the PNG file reader
>>code that is currently in place. I noticed that it was causing the
>>program to crash when the program was exiting (on the last bracket of
>>main() ) while calling of destructors for ImageIO and such, as well as
>>cleaning up the smart pointers. Miraculously, this crashing went away as
>>soon as the image reader (and corresponding factory) was added to the
>>ITKIO library. Has anybody had similar problems or have any idea why this
>>was happening when the code was external to ITK?
>>
>>wilson
>>
>>_______________________________________________
>>Insight-developers mailing list
>>Insight-developers@public.kitware.com
>>http://public.kitware.com/mailman/listinfo/insight-developers
>
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers