[Insight-users] Re: About using Delete() of itk::ProcessObject

Luis Ibanez luis.ibanez at kitware.com
Tue May 1 19:24:03 EDT 2007



Hi Sonali,



             You description is not clear.



Here is what I can gather:

1) You are writing a new filter.

2) One method of this filter returns a Pointer to an
    object X of type MapContainer that you defined.

3) You don't let us know when that object X was created.

4) You don't let us know if your filter has a member variable
    holding a SmartPointer to object X.

5) You don't let us know how you are deleting object X
    in your example. What from the subject of your email
    we are left to assume that you are calling the Delete()
    method on it.

6) With that assumption we can tell you that you should
    *NEVER* call the Delete() method in a smart pointer.

7) With the same assumption we can see that you have not
    read the Tutorials:
    http://www.itk.org/HTML/Tutorials.htm
    and in particular not the first Tutorial:
http://www.itk.org/CourseWare/Training/GettingStartedI-WebPage/index.htm


Based on these assumptions... we could suggest you should
make the SmartPointer to the object X of type MapContainter
to be a member variable of your filter, and that your method
that return this smart pointer should return a ConstPointer,
to ensure that from outside your filter, this object can't
be destroyed.



    Regards,



       Luis



-----------------------
Sonali Barua wrote:
> Hello,
> 
> I am developing a filter. In one of the methods  a Pointer to an object 
> of a MapContainer type that I have defined is returned. When the object 
> in the example file is deleted, the object referenced within the filter 
> is deleted as well and during  run time I get a Segmentation fault 
> during the second run of the filter. When I don't delete the object 
> defined in the example file, the filter runs fine the second time. Is 
> there anyway that I can delete the object in the example file and not 
> have it effect the one in the filter?
> 
> Sincerely,
> 
> Sonali Barua.


More information about the Insight-users mailing list