[Insight-users] destruction of smart pointers
dean.inglis@on.aibn.com
dean.inglis@on.aibn.com
Sun, 16 Feb 2003 9:08:39 -0500
Hi John,
in the constructor, if I don't create the itk
pointer with ::New() and then try ot use it in the
Form's constructor, I get an access violation that
points to the Form's constructor. AFAIK most of the
Insight/Applications with GUIs declare itk member
objects in the same way ( pointer in the class
definition):
itk::SomeObjectType::Pointer SomeObject;
and then construct in the app's constructor: SomeObject = SomeObjectType::New();
There is no pointer destruction problem when declaring an itk object within the form's constructor and then increasing the reference count by one to force its persistence beyond the scope of
the constructor. However, I would have to create a lot of callback type code so that using the name of
the pointer is avoided elseware in the app.
Have you tried any tests with itk & Borland GUI app's that work?
Dean
>
> From: "John Biddiscombe" <jbiddiscombe@skippingmouse.co.uk>
> Date: 2003/02/16 Sun AM 04:35:47 GMT-05:00
> To: <dean.inglis@on.aibn.com>, <insight-users@public.kitware.com>
> Subject: Re: [Insight-users] destruction of smart pointers
>
> 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
> >
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>