[vtk-developers] vtkLoopSubdivisionFilter

Robert Maynard robert.maynard at kitware.com
Mon Jul 18 14:30:46 EDT 2011


Hi,

This looks like a perfect place to use vtkNew instead of creating
those as pointers.

On Mon, Jul 18, 2011 at 2:28 PM, Laurent Chauvin
<lchauvin at bwh.harvard.edu> wrote:
> Ok. Thank you.
>
> You're right, this is not the first time I see this kind of issue.
> Using a return is not always the best solution, because this is interupting
> the function, and could cause some issues (like objects not deleted ->
> memory leaks).
>
> Thank you for your replies.
> -Laurent
>
> On Mon, Jul 18, 2011 at 2:25 PM, David Doria <daviddoria at gmail.com> wrote:
>>
>> On Mon, Jul 18, 2011 at 2:20 PM, Laurent Chauvin
>> <lchauvin at bwh.harvard.edu> wrote:
>>>
>>> Hello,
>>>
>>> I was using vtkLoopSubdivisionFilter, but after leaving Slicer I got
>>> hundred of thousands of vtkIdList leaks.
>>>
>>> After debugging, the problem seems to come from this part of code:
>>>
>>> void vtkLoopSubdivisionFilter::GenerateEvenStencil (vtkIdType p1,
>>>                                                     vtkPolyData *polys,
>>>                                                     vtkIdList
>>> *stencilIds,
>>>                                                     double *weights)
>>> {
>>>   vtkIdList *cellIds = vtkIdList::New();
>>>   vtkIdList *ptIds = vtkIdList::New();
>>>   vtkCell *cell;
>>>
>>>   int i, j;
>>>   int numCellsInLoop;
>>>   int startCell, nextCell;
>>>   vtkIdType p, p2;
>>>   vtkIdType bp1, bp2;
>>>   int K;
>>>   double beta, cosSQ;
>>>
>>>   // Get the cells that use this point
>>>   polys->GetPointCells (p1, cellIds);
>>>   numCellsInLoop = cellIds->GetNumberOfIds();
>>>   if (numCellsInLoop < 1)
>>>       {
>>>       vtkWarningMacro("numCellsInLoop < 1: " << numCellsInLoop);
>>>       stencilIds->Reset();
>>>
>>>       // Test Remove vtkIdList
>>>       cellIds->Delete();
>>>       ptIds->Delete();
>>>       // End Test
>>>
>>>       return;
>>>       }
>>>   // Find an edge to start with that contains p1
>>>
>>> ...
>>> cellIds->Delete();
>>> ptsIds->Delete();
>>> }
>>>
>>> If we return before the end of the function, the cellIds and ptsId are
>>> not deleted (creating leaks).
>>> I had the code between comments "Test Remove vtkIdList" and "End Test".
>>>
>>> Leaks are gone.
>>>
>>> I just would like to know if it was a mistake or if there is a reason for
>>> not deleting before returning ?
>>>
>>> Thank you.
>>> -Laurent
>>>
>>> --
>>> Laurent Chauvin, MS
>>
>> Seems like an oversight. I've seen that same type of thing in one or two
>> cases before. That seems to be the right fix to me.
>>
>> David
>
>
> --
> Laurent Chauvin, MS
> Surgical Planning Laboratory, Radiology
> Brigham And Women's Hospital, Harvard Medical School
> http://wiki.ncigt.org/index.php/User:Lchauvin
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>



-- 
Robert Maynard



More information about the vtk-developers mailing list