[vtkusers] What exactly happens in this scenario?
Bill Lorensen
bill.lorensen at gmail.com
Fri Jun 25 07:55:03 EDT 2010
Yes, it will leak.
To prevent the leak,, in your constructor,
elementNumberActor = NULL;
In DisplayElementNumbers() before assigning the actor,
if (elementNumberActor != NULL)
{
elementNumberActor->Delete();
}
In the destuctor,
if (elementNumberActor != NULL)
{
elementNumberActor->Delete();
}
On Fri, Jun 25, 2010 at 7:43 AM, Rakesh Patil <rakeshthp at in.com> wrote:
> Hello,
>
> I want to know what exactly happens in this scenario. I have a C++ class
> say, "myClass"
>
> myClass
> {
> ...
> vtkActor2D *elementNumberActor;
> ...
> public:
> ... // Constructors and destructors
>
> void DisplayElementNumbers();
> ...
> };
>
> Now, i have the function body as follows:
>
> void myClass::DisplayElementNumbers()
> {
> vtkIdFilter *ids = vtkIdFilter::New();
> ids->SetInputConnection( programmableFilter-> GetOutputPort() );
> ids->CellIdsOn();
> ids->FieldDataOn();
>
> vtkCellCenters *cellC = vtkCellCenters::New();
> cellC->SetInputConnection( ids->GetOutputPort() );
>
> vtkSelecttVisiblePoints *vispts = vtkSelectVisiblePoints::New();
> vispts->SetInputConnection( cellC->GetOutputPort() );
> vispts->SetRenderer( pRenderer );
>
> vtkLabelDataMapper *ldm = vtkLabelDataMapper::New();
> ldm->SetInputConnection( vispts->GetOutput Port() );
> ldm->SetLabelModeToLabelFieldData();
>
> elementNumberActor = vtkActor2D::New();
> elementNumberActor->SetMapper (ldm );
>
> ldm->Delete();
> vispts->Delete();
> cellC->Delete();
> ids->Delete();
>
> }
>
> Well, the statement in the box is
>
> elementNumberActor = vtkActor2D::New();
>
> If i call this function again and again, will this statement cause in memory
> leak ??
> How and what will be the performance of my application??
>
> Thanks in advance
>
> Regards
> Rakesh Patil
>
>
> Dear VTK ! Get Yourself a cool, short @in.com Email ID now!
> _______________________________________________
> 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
>
>
More information about the vtkusers
mailing list