[Insight-developers] Memory leaks in Mesh

Miller, James V (Research) millerjv@crd.ge.com
Tue, 1 Oct 2002 13:01:19 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C26969.C7A2BAB0
Content-Type: text/plain;
	charset="iso-8859-1"

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?

 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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 

 

 

------_=_NextPart_001_01C26969.C7A2BAB0
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=627004416-01102002><FONT size=2>I am trying to track down the 
memory leaks in the mesh class.&nbsp; </FONT></SPAN></DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2>It looks like 
Mesh::SetCell(CellIdentifier, CellAutoPointer&amp;) leaks memory if there was 
already a cell assigned at the specified CellIdentifier location.&nbsp; The 
cells are ultimately kept in a vector of pointers to cells (not SmartPointers, 
not AutoPointers).&nbsp; So, SetCell() just overwrites the location in the 
vector with a new pointer to a cell.</FONT></SPAN></DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2>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().&nbsp; This should be documented somewhere. 
I modified the itkMeshTest to do this deallocation.</FONT></SPAN></DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=627004416-01102002><FONT size=2>It also looks like 
Mesh::GetCellBoundaryFeature() leaks when it is asked for&nbsp;the 
same&nbsp;"implicit" boundary feature multiple times.&nbsp; 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).&nbsp; This created feature gets 
inserted into the vector of boundary features.&nbsp; 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.&nbsp; This 
causes a leak.&nbsp; 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.&nbsp; 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&nbsp;NOT&nbsp;added to the list of&nbsp;ASSIGNED boundary features.&nbsp; 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?</FONT></SPAN></DIV>
<DIV class=Section1>
<P class=MsoNormal>&nbsp;<?xml:namespace prefix = o ns = 
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></P>
<P style="MARGIN: 0in 0in 0pt"><B><SPAN 
style="COLOR: navy; FONT-FAMILY: 'Comic Sans MS'">Jim Miller</SPAN></B> 
<BR><B><I><SPAN 
style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: Arial">_____________________________________</SPAN></I></B><BR><EM><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">Visualization &amp; 
Computer Vision</SPAN></EM><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial"><BR><EM>GE 
Research</EM><BR><EM>Bldg. KW, Room C218B</EM><BR><EM>P.O. Box 8, Schenectady NY 
12301</EM><BR><BR></SPAN></I><EM><U><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: blue"><A 
href="mailto:millerjv@research.ge.com">millerjv@research.ge.com</A></SPAN></U></EM></P>
<P style="MARGIN: 0in 0in 0pt"><EM><U><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: blue">james.miller@research.ge.com</SPAN></U></EM><BR><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">(518) 387-4005, Dial 
Comm: 8*833-4005, </SPAN></I><BR><I><SPAN 
style="FONT-SIZE: 7.5pt; COLOR: black; FONT-FAMILY: Arial">Cell: (518) 505-7065, 
Fax: (518) 387-6981</SPAN></I> </P>
<P class=MsoNormal>&nbsp;<o:p></o:p></P></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C26969.C7A2BAB0--