[vtkusers] memory leak in vtkConstrainedPointHandleRepresentation VTK 5.8.0
David E DeMarle
dave.demarle at kitware.com
Thu May 10 11:25:48 EDT 2012
Thanks Alex,
I've pushed this for review here: http://review.source.kitware.com/#/t/598
and assuming it gets through the dashboards and review process it will
make it into VTK 5.10 and up.
David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909
On Wed, May 9, 2012 at 7:28 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
> I attached modification of cube example in order to reproduce the leak.
> In addition you need to link against widget.lib which original cube
> does not have as dependency listed.
>
> After you start executable and see the cube,
> click on it and draw the distant widget.
>
> If you exit now you will see a plenty of leaks in:
> vtkMatrix
> vtkAssemblyPath
> vtkAssemblyNode
> vtkTransform
>
>
> To fix these leaks you need to patch
> vtkConstrainedPointHandleRepresentation::GetIntersectionPosition
> as below.
>
> All lines changed or important are commented
> and all comments are mine.
>
> This definitely fixes leaks for me.
> If anybody could patch official/developer version I would appreciate.
>
> Best regards,
> Alex.
>
> int vtkConstrainedPointHandleRepresentation::GetIntersectionPosition(double
> eventPos[2],
>
> double worldPos[3],
>
> double tolerance,
>
> vtkRenderer * renderer)
> {
> ... ... ...
> vtkCellPicker *picker = vtkCellPicker::New();
>
> picker->Pick(eventPos[0], eventPos[1], 0, renderer);
>
> // why not to use smart pointer below ???
>
> vtkAssemblyPath *path = picker->GetPath();
>
> if(path == 0)
> {
>
> // since smart pointer is not used add line below
>
> picker->Delete();
> return 0;
> }
> double pickPos[3];
> picker->GetPickPosition(pickPos);
> path->Register(this);
> if ( this->BoundingPlanes )
> {
> vtkPlane *p;
> this->BoundingPlanes->InitTraversal();
> while ( (p = this->BoundingPlanes->GetNextItem()) )
> {
> double v = p->EvaluateFunction( pickPos );
> if ( v < tolerance )
> {
> return 0;
> }
> }
> }
>
> worldPos[0] = pickPos[0];
> worldPos[1] = pickPos[1];
> worldPos[2] = pickPos[2];
>
> // as I understand the code path->Register(this);
> // added reference count
> // I am not sure if it is necessary in the first place,
> // but if it is done we need to remove reference counter
> // to prevent memory leak,
> // which is done at the next line
> path->Delete();
>
> picker->Delete();
>
> return 1;
> }
>
>
>
>
> On Tue, May 8, 2012 at 9:35 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
>> Actually to get memory leak with code below you need to start interaction,
>> so add the following after the code below :
>>
>> distanceWidget->On();
>>
>> and click to add points,
>>
>> It looks like memory leak is related to the Glyph3D usage,
>> but I could not find an exact place where it happens,
>>
>> Any help is appreciated.
>>
>> Alex
>>
>>
>> On Mon, May 7, 2012 at 8:35 PM, Alex Malyushytskyy <alexmalvtk at gmail.com> wrote:
>>> It looks like that there is a memory leak in
>>> vtkConstrainedPointHandleRepresentation .
>>> ( at least VTK 5.8.0, MSVS2010)
>>>
>>> I am trying to use vtkDistanceWidget which is initialized as:
>>>
>>> vtkSmartPointer< vtkConstrainedPointHandleRepresentation > handleRep
>>> = vtkSmartPointer< vtkConstrainedPointHandleRepresentation >::New();
>>> vtkSmartPointer< vtkDistanceRepresentation2D > distanceRep =
>>> vtkSmartPointer< vtkDistanceRepresentation2D >::New();
>>>
>>> distanceRep->SetHandleRepresentation( handleRep );
>>>
>>> distanceRep->SetLabelFormat("%-#6.5g in");
>>> distanceRep->RulerModeOff( );
>>> distanceRep->SetRulerDistance( 120. );
>>>
>>> distanceWidget = vtkSmartPointer<vtkDistanceWidget>::New();
>>> distanceWidget->SetInteractor( GetRenderWindow()->GetInteractor() );
>>> distanceWidget->SetRepresentation( distanceRep );
>>> distanceRep->InstantiateHandleRepresentation();
>>> distanceWidget->CreateDefaultRepresentation();
>>> distanceWidget->EnabledOff();
>>>
>>>
>>> When application exits I get VTK notification about memory leaks.
>>> If I replace vtkConstrainedPointHandleRepresentation with
>>> vtkPointHandleRepresentation2D
>>> there is no memory leak (but I do not get default behavior)
>>>
>>> Could anybody who has access to nightly version check if there were any patches?
>>>
>>> Regards,
>>> Alex
>
> _______________________________________________
> 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