[vtkusers] This code gives memory leak.. Why?

Aashish Chaudhary aashish.chaudhary at kitware.com
Wed Jul 7 10:21:48 EDT 2010


quickly looking

you would have to call delete on contourActor

as when you do AddActor that will also increment the ref count.

Use vtkSmartPointer.



On Wed, Jul 7, 2010 at 9:58 AM, Rakesh Patil <rakeshthp at in.com> wrote:

> Hello,
>
> I have this particular function to display contours.. When i iterate this
> through a loop, for different timestep,
> each time, i set new set of scalars for unstructuredGrid (uGrid) through
> the means of bathyArray.
> I get the desired output as i need, but i see that there exists some memory
> leak.. at each iteration, some amount
> of memory is being held.. I dont know by whom and where.. Below is the code
>
> myClass
> {
> ...
> vtkActor2D *element NumberActor;
> ...
> public:
> ... // Constructors and destructors
>
> void DisplayContour();
> ...
> };
>
> Now, i have the function body as follows:
>
> void myClass::DisplayConto ur()
> {
>
> uGrid->GetPointData()->SetScalars( bathyArray);
> uGrid->Update();
>
> vtkGeometryFilter *gf = vtkGeometryFilter::New();
> gf->SetInput( uGrid );
>
> vtkThreshold *thr = vtkThreshold::New();
> thr->SetInputConnection( gf->GetOutputPort() );
> thr->ThresholdByUpper( BAD_VALUE );
> thr->Update();
>
> vtkContourGrid *contGrid = vtkContourGrid::New();
> contGrid->SetInputConnection( thr->GetOutputPort());
> contGrid->GenerateValues(n, dataRange);
>
> vtkDataSetMapper *ldm = vtkDataSetMapper::New();
> ldm->Set InputConnection( contGrid->GetOutputPort() );
> ldm->SetScalarRange( dataRange);
>
> pRenderer->RemoveActor(contourActor);
>
> if(contourActor)
> {
> contourActor->Delete();
> contourActor = NULL;
> }
>
> contourActor = vtkActor::New();
> contourActor->SetMapper(ldm);
> pRenderer->AddActor( contourActor );
>
> gf->Delete();
> thr->Delete();
> contGrid->Delete();
> ldm->Delete();
>
> }
>
>
> Can anyone help me or give some clue as what is the mistake i have been
> doing..?? What can i do to avoid this memory leaks.,?
>
> Thanks in advance
>
> Regards
> Rakesh P atil
>
>
> Dear *vtkusers !* Get Yourself a cool, short *@in.com* Email ID now!<http://mail.in.com/mails/new_reg.php?utm_source=invite&utm_medium=outgoing>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>


-- 
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100707/63986f3a/attachment.htm>


More information about the vtkusers mailing list