[Insight-users] destruction of itk objects

dean.inglis@on.aibn.com dean.inglis@on.aibn.com
Thu, 13 Feb 2003 9:55:01 -0500


Hi,

GUI development in BCB5 typcially consists of
creating a blank 'form' and dropping buttons,
sliders etc. on it.  The 'form' inherits from a
base class and has methods such as OnCreate, OnShow,
OnDestroy etc.  Usually one instantiates objects
in the OnCreate event and deletes them during 
OnDestroy. With VTK objects this works fine. With
itk objects I am getting access violations that
point to the virtual destructor in itkSource.h.
So, for example, the form class owns a public

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

instantiates it in the OnCreate event:

vtkImporter = vtkImageImport::New();

but in the OnDestroy event, what should be done?
With Borland GUI apps, there is an 'Application'
class that manages the run:

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->CreateForm(__classid(TForm1), &Form1);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        return 0;
}

So, the application runs until the form is 
exited/shut down and I'm guessing the itk smart
pointer is trying to delete after(?) the form
destroys itself???

Can I enforce deletion of itk objects and overide
smart pointer behaviour?

Dean