[vtkusers] What exactly happens in this scenario?

Xiaofeng Z xf10036 at hotmail.com
Fri Jun 25 11:10:51 EDT 2010


Or to use smart pointer, at least for vtkActor2D

x.z.


 
> Date: Fri, 25 Jun 2010 07:55:03 -0400
> From: bill.lorensen at gmail.com
> To: rakeshthp at in.com
> CC: vtkusers at vtk.org
> Subject: Re: [vtkusers] What exactly happens in this scenario?
> 
> 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
> >
> >
> _______________________________________________
> 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
 		 	   		  
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100625/fb0f2bd6/attachment.htm>


More information about the vtkusers mailing list