[Insight-users] destruction of smart pointers

dean.inglis@on.aibn.com dean.inglis@on.aibn.com
Sat, 15 Feb 2003 23:08:48 -0500


still trying to get Borland GUI working here.
I did a simple test: in my Form class definition 
I have in the public section:

typedef itk::Image<float, 2> ImageType;
typedef itk::VTKImageImport<ImageType>
ImageImportType;
ImageImportType::Pointer itkImporter;

in the Form's constructor, I try to create and
then immediately destroy the pointer:

  itkImporter = ImageImportType::New();
  itkImporter->DebugOn();
  itkImporter->UnRegister();

the Win32 OuputWindow shows the Reference count goes
to zero and the pointer destructs.  However, after
running and then exiting the app, the debugger shows
the line 

  void UnRegister()
    {
***->    if(m_Pointer) { m_Pointer->UnRegister(); }
    }

in itkSmartPointer.h as being the cause of an access
violation.  Is there some other itk object that
need to be destroyed that I am missing? I am stumped ... but am determined to  get GUI development working with BCB5 and ITK!
Can someone explain to me the difference(s) in 
terms of object persistence/lifetime between
typical class pointers and SmartPointers. i.e.,
if it were a VTK class object:
 vtkSomeClass* vtkPtr;

one can do this: 
  vtkPtr = 0;
and
  vtkPtr = vtkSomeClass::New();
and 
  vtkPtr->Destroy();
and maybe again
  vtkPtr = 0;

One always 'knows' what one is getting in terms of
pointer validity/existence.  How does this compare
with itk smart pointers?  Perhaps its obvious, but
I need to be hit on the head here ...

Dean