[Insight-users] BCB5 and itk - please help

Bill Hoffman bill.hoffman@kitware.com
Wed, 19 Feb 2003 14:37:14 -0500


This code should crash with any compiler.


At 11:30 AM 2/19/2003 +0000, John Biddiscombe wrote:

>Dean
>
>Does it still crash if you do this...
>filter = FilterType::New();  // object is born with reference count of 1
>filter->Unregister();    // object is deleted as reference count goes to 0
>filter = NULL;   // smart pointer calls UnRegister, and it crashes because the pointer has already been deleted.

Basically, you can never have an UnRegister without a Register.
All a smart pointer does is encapsulate the Register in the constructor
and the UnRegister in the destructor.

-Bill



>ie explicitly delete the filter and set the pointer to null before exit.