[Insight-developers] Memory leaks in Mesh

Luis Ibanez luis.ibanez@kitware.com
Tue, 01 Oct 2002 13:56:42 -0400


Hi Jim,

It looks like the Mesh requires a major refactoring.

There is a large set of functionalities provided by
the Mesh that don't seem to be used by the toolkit
but cost a lot on the implementation.  For example
the management of neighborhood relationships
between cells and the policy of simulating explicit
cells. Most of the dificulties in memory managment
come from these features.

How about having a discussion on the use/design
of the Mesh at next week meeting. Probably on
Tuesday  ?


   Luis


======================================

Miller, James V (Research) wrote:

> I am trying to track down the memory leaks in the mesh class. 
>
>  
>
> It looks like Mesh::SetCell(CellIdentifier, CellAutoPointer&) leaks 
> memory if there was already a cell assigned at the specified 
> CellIdentifier location.  The cells are ultimately kept in a vector of 
> pointers to cells (not SmartPointers, not AutoPointers).  So, 
> SetCell() just overwrites the location in the vector with a new 
> pointer to a cell.
>
>  
>
> This means the user of the Mesh has to manage the de-allocation of the 
> cell currently at the CellIdentifier position prior to calling 
> SetCell().  This should be documented somewhere. I modified the 
> itkMeshTest to do this deallocation.
>
>  
>
> It also looks like Mesh::GetCellBoundaryFeature() leaks when it is 
> asked for the same "implicit" boundary feature multiple times.  When 
> asked for an implicit boundary feature, memory get allocated to hold 
> the feature (i.e. when asking for an edge of a triangle where the 
> triangle is just specified with 3 vertices but no explicit edges are 
> defined).  This created feature gets inserted into the vector of 
> boundary features.  When called a second time for the same implicit 
> boundary feature, memory gets allocated for the feature and the 
> feature overwrites the previously created boundary feature.  This 
> causes a leak.  There is a check in the code that if the cell boundary 
> feature is one of the "assigned" boundary features (explicit 
> features), then it simply returns the feature from the boundary 
> feature vector.  However, when a boundary feature is implicit, an 
> object is created to be returned to the user and that object is added 
> to the vector of boundary features but that object is NOT added to the 
> list of ASSIGNED boundary features.  So the check in the code fails 
> and a new feature is allocated and overwrites the previous boundary 
> feature pointer in the boundary feature vector. Once an implicit 
> feature is queried, should it be converted (and recorded) as an 
> explicit and assigned feature?
>
>  
>
> * Jim Miller*
> */_____________________________________/*
> / Visualization & Computer Vision//
> /GE Research/
> /Bldg. KW, Room C218B/
> /P.O. Box 8, Schenectady NY 12301/
>
> //_ millerjv@research.ge.com <mailto:millerjv@research.ge.com> _/
>
> /_ james.miller@research.ge.com_/
> /(518) 387-4005, Dial Comm: 8*833-4005, /
> /Cell: (518) 505-7065, Fax: (518) 387-6981/
>
>  
>
>  
>