[Insight-users] destruction of smart pointers - more
John Biddiscombe
John Biddiscombe" <jbiddiscombe@skippingmouse.co.uk
Sun, 16 Feb 2003 09:25:38 -0000
Dean
>>>
> > 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;
<<<
You mean this is in the form.h file in the class definition (I think I
misunderstood before). In that case the lifetime of the
(ImageImportType::Pointer itkImporter) is from the beginning of the
constructor until the end of the destructor. The object has scope as long as
the form exists. Don't delete it at all. The destructor of your form will
delete the smartpointer and the object will then die.
JB
----- Original Message -----
From: <dean.inglis@on.aibn.com>
To: <dean.inglis@on.aibn.com>; <insight-users@public.kitware.com>
Sent: Sunday, February 16, 2003 4:28 AM
Subject: Re: [Insight-users] destruction of smart pointers - more
> Ok, the call stack shows:
>
> 004042AE
itk::SmartPointer<itk::VTKImageImport<itk::Image<float,2>>>::UnRegister(this
=:09FF2FE0)
> 00404220
>
itk::SmartPointer<itk::VTKImageImport<itk::Image<float,2>>>::~SmartPointer<i
tk::VTKImageImport<itk::Image<float,2>>>(this=:09FF2FE0)
> 00404886 TForm1::~TForm1(this=:09FF2CE4)
> 0046A96D Classes::TComponent::DestroyComponents
> 0048DB17 __init_exit_proc
> 0048DB66 __cleaup
> 0048CE28 _exit
> 0048DD3C ___startup
>
> Does this mean that after the class that owns the
> itk pointer object (as a class member) is destroyed,
> the smart pointer, which should not exist, is trying
> to destroy itself???
>
> Dean
>
> >
> > 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
>