[Insight-users] Re: how to release the memory of a filter

Karthik Krishnan Karthik.Krishnan at kitware.com
Thu Mar 16 17:14:07 EST 2006



Andrew Li wrote:

>Hi, Karthik:
>
>Your answers to Alb helped me too.
>I have some additional questions:
>
>What will happen if I do the following? (Assuming that TmpImage is also
>a smart pointer)
>
>  
>
>>>...
>>>
>>>itkFilter1->SetInput( InputImage );
>>>itkFilter1->Update();
>>>TmpImage = itkFilter1->GetOutput();
>>>
>>>      
>>>
>
>InputImage = 0; // added as suggested by Karthik
>itkFilter1 = 0; // added by Andrew #1
>
>  
>
>>>MyClassObject.SetInput( TmpImage );
>>>OutputImage = MyClassObject.GetOutput();
>>>
>>>      
>>>
>
>TmpImage = 0; // added by Andrew #2
>
>  
>
>>>...
>>>
>>>      
>>>
>
>
>Is there any advantage or problem from this inserted line? 
>	itkFilter1 = 0; // added by Andrew #1
>I assume that this line will force everything pointed by itkFilter1 to
>be released except the object pointed by TmpImage. Is it correct?
>  
>
yes, if itkFilter1 is the only one maintaining a reference to InputImage.

>And the remaining resources: the object pointed by TmpImage will be
>release at inserted line #2: 
>	TmpImage = 0; // added by Andrew #2
>And, thus, there will be no problem such as memory leaks.
>  
>
Sure. Sometimes its just easier to use the releasedataflag instead of 
having to remember reference counts...
see http://article.gmane.org/gmane.comp.lib.itk.user/8849

> 
>Thank you very much for your help!
>
>-Andrew
> 
>--------------------------------------------------------
>
>This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information.Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. If you are the intended recipient, please be advised that the content of this message is subject to access, review and disclosure by the sender's Email System Administrator.
>--------------------------------------------------------
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>
>  
>


More information about the Insight-users mailing list