[vtkusers] vtk Filter's new/delete

David Cole david.cole at kitware.com
Tue Dec 23 08:46:43 EST 2008


Your "fun" function assisns to *pLSPoints. The pLSPoints parameter is an
output of the function. Therefore, you need to call LSPoints->Delete()
*before* calling fun in the calling function...

2008/12/23 chensiqi <pidanchen at hotmail.com>

>  Hi, vtkers.
>
> I have a question regarding pointer new and delete. Here is the code
>
> main(){
> ....
>  vtkPoints *LSPoints = vtkPoints::New();
>  fun ( LSV, &LSPoints );
>  std::cout<<
> LSPoints->GetNumberOfPoints()<<std::endl;.......................................(1)
> ....
>  LSPoints->Delete();
> }
>
> fun( vtkImage LSV, vtkPoints **pLSPoints )
> {
>  vtkContourFilter *LSFilter = vtkContourFilter::New();
>  LSFilter->SetInput( vtkLSV );
>  LSFilter->SetValue( 0, 0 );
>  LSFilter->Update();
>  *pLSPoints = LSFilter->GetOutput()->GetPoints();
>  std::cout<<
> (*pLSPoints)->GetNumberOfPoints()<<std::endl;.................................(2)
>  LSFilter->Delete();
> }
>
> The output at position 2 is correct where as the output at position 1 is
> destroyed.
> If I comment "LSfilter->Delete()", then the output at both locations are
> correct.  But I think I need to release the memory of LSFilter here.
>
> pls point out where I am wrong.
>
> Thanks for any input.
> Siqi
>
>
>
>
>
> ------------------------------
> 更多热辣资讯尽在新版MSN首页! 立刻访问! <http://cn.msn.com/>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081223/9074a5b1/attachment.htm>


More information about the vtkusers mailing list