[vtk-developers] vtkLoopSubdivisionFilter

Laurent Chauvin lchauvin at bwh.harvard.edu
Mon Jul 18 14:28:28 EDT 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110718/6c760e66/attachment.html>


More information about the vtk-developers mailing list