[Insight-users] destruction of smart pointers
John Biddiscombe
John Biddiscombe" <jbiddiscombe@skippingmouse.co.uk
Sun, 16 Feb 2003 09:35:47 -0000
Another thing...
if you have
class myform : public anotherform {
public:
typedef itk::Image<float, 2> ImageType;
typedef itk::VTKImageImport<ImageType>
ImageImportType;
ImageImportType::Pointer itkImporter;
}
the in the cpp you do not need to "create" an instance of itkImporter at
all, it is created for you. This is your trouble. You've done this
constructor {
BCB has already created an object of type ImageImportType::Pointer called
itkImporter
//
itkImporter = ImageImportType::New();
itkImporter->DebugOn();
itkImporter->UnRegister();
// What have you done. - you've created another instance of
ImageImportType - and guess what - it's got the same name as the other one
"itkImporter",
// in the destructor, you delete it (fine), and then BCB deletes the
original one as well (oops), jusr remove ALL your code and "hey presto", all
should be well (barring anything I've missed)
}
JB
----- Original Message -----
From: <dean.inglis@on.aibn.com>
To: <insight-users@public.kitware.com>
Sent: Sunday, February 16, 2003 4:08 AM
Subject: [Insight-users] destruction of smart pointers
> 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
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>