[Insight-users] destruction of itk objects

dean.inglis@on.aibn.com dean.inglis@on.aibn.com
Thu, 13 Feb 2003 11:03:19 -0500


Hi John,

I was hoping you would respond!  Well, that 
doesn't work either.  In OnCreate I have:

  itkImporter = ImageImportType::New();
  itkImporter->Register();
  itkImporter->DebugOn();
  itkImporter->SetGlobalWarningDisplay(true);

I added a button on the form to pop up a ShowMessage
with the reference count: clearly the itk object 
exists: GetReferenceCount = 2.

In the OnDestory event,
 itkImporter->UnRegister(); 
the IDE debug shows this as the problem line: it
causes an access violation.  Commenting that line
out,  and the debugger moves on to the UnRegister method in itkSmartPointer.h:
if(m_Pointer){ m_Pointer->UnRegister()};

and the debug info never pops up.

BTW, itkImporter is not connected to anything else,
just trying to instantiate and have it destroy in a
BCB5 gui app. Should I override the form's destructor?

I've also posted to one of the Borland newsgroups.

thanks,
Dean

> 
> From: "John Biddiscombe" <jbiddiscombe@skippingmouse.co.uk>
> Date: 2003/02/13 Thu AM 10:42:36 GMT-05:00
> To: <dean.inglis@on.aibn.com>, 
> 	<insight-users@public.kitware.com>
> Subject: Re: [Insight-users] destruction of itk objects
> 
> Dean
> 
> > typedef itk::Image<float, 2> ImageType;
> > typedef itk::VTKImageImport<ImageType> ImageImportType;
> > ImageImportType::Pointer itkImporter;
> >
> > instantiates it in the OnCreate event:
> 
> At the end of the OnCreate itImporter gets destroyed because it's out of
> scope
> 
> add
> itkImporter->Register()
> 
> and in OnDestroy put
> itkImporter->UnRegister()
> 
> to make sure it "exists" in between
> 
> JB
> 
> 
>