Is it a memory leak

AoA 
        I have used standard template library in one of my applications. I 
belive that memory leaks are due to stl components, mainly string. i wrote a 
sample program in VC 6.0 that clearly shows memory leaks in stl 

wstring str = L""; 
  for( int a = 0 ; a < 100000 ; a++ ) 
  { 
   str += L"int"; 
  } 
  str.str.erase( str.begin() , str.end() ); 
  str = L"int"; 

i wrote this code against a button in dialog based application. Before 
clicking the button, the memory usage is 3MB and after this code it is 17MB 
although i believe it should have been back to 3MB after the statement 
str.erase( str.begin() , str.end() ). 

My other observation is that if i exit the application in debug mode it 
tells almost everything about the memory leaks except for the file from which 
memory was allocated. I copied a code that would tell the file but it would 
all leaks are from crtdbg.h 

anyone plz give me a solution to this.any help in this regard will be highly 
appreciated. 
P.S. I have been using Task Manager to see how much memory is bieng used by 
my application. 
Regards 
Omar Javed
0
Javed (5)
9/3/2004 3:25:05 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
846 Views

Similar Articles

[PageSpeed] 51

Omar Javed wrote:
> P.S. I have been using Task Manager to see how much memory is bieng used by 
> my application. 
> Regards 
> Omar Javed

Task Manager provides no useful information about how much memory is 
being used by your application.  The behavior you see is normal: The 
runtime library is part of your program, and it keeps the allocated 
address space for reuse.  In a virtual memory system such as Windows, 
this does not mean that the memory is dedicated to your program.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
9/3/2004 5:10:05 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0092_01C491EB.2250F6D0
Content-Type: text/plain;
	charset="gb2312"
Content-Transfer-Encoding: quoted-printable

In my system, before this piece of code, the memory occupied by my =
program is 770k, and after it is 1550k.
As Scoot says, this is not a sign of memory leak. All of the things is =
just alright including your code. Perhaps you should review your program =
and try to find other possible reasons.

ATField
  "Omar Javed" <Omar Javed@discussions.microsoft.com> wrote in message =
news:4FAD2FEA-4816-4FEC-95CF-35C2B6F0873B@microsoft.com...
  AoA=20
          I have used standard template library in one of my =
applications. I=20
  belive that memory leaks are due to stl components, mainly string. i =
wrote a=20
  sample program in VC 6.0 that clearly shows memory leaks in stl=20

  wstring str =3D L"";=20
    for( int a =3D 0 ; a < 100000 ; a++ )=20
    {=20
     str +=3D L"int";=20
    }=20
    str.str.erase( str.begin() , str.end() );=20
    str =3D L"int";=20

  i wrote this code against a button in dialog based application. Before =

  clicking the button, the memory usage is 3MB and after this code it is =
17MB=20
  although i believe it should have been back to 3MB after the statement =

  str.erase( str.begin() , str.end() ).=20

  My other observation is that if i exit the application in debug mode =
it=20
  tells almost everything about the memory leaks except for the file =
from which=20
  memory was allocated. I copied a code that would tell the file but it =
would=20
  all leaks are from crtdbg.h=20

  anyone plz give me a solution to this.any help in this regard will be =
highly=20
  appreciated.=20
  P.S. I have been using Task Manager to see how much memory is bieng =
used by=20
  my application.=20
  Regards=20
  Omar Javed
------=_NextPart_000_0092_01C491EB.2250F6D0
Content-Type: text/html;
	charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2800.1458" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>In my system, before&nbsp;this piece of =
code, the=20
memory occupied by my program is 770k, and after it is =
1550k.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>As Scoot says, this is not a sign of =
memory leak.=20
All of the things is just alright&nbsp;including your code. Perhaps you =
should=20
review your program and&nbsp;try to find other&nbsp;possible=20
reasons.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>ATField</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV>"Omar Javed" &lt;Omar <A=20
  =
href=3D"mailto:Javed@discussions.microsoft.com">Javed@discussions.microso=
ft.com</A>&gt;=20
  wrote in message <A=20
  =
href=3D"news:4FAD2FEA-4816-4FEC-95CF-35C2B6F0873B@microsoft.com">news:4FA=
D2FEA-4816-4FEC-95CF-35C2B6F0873B@microsoft.com</A>...</DIV>AoA=20
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I have used standard =
template=20
  library in one of my applications. I <BR>belive that memory leaks are =
due to=20
  stl components, mainly string. i wrote a <BR>sample program in VC 6.0 =
that=20
  clearly shows memory leaks in stl <BR><BR>wstring str =3D L""; =
<BR>&nbsp; for(=20
  int a =3D 0 ; a &lt; 100000 ; a++ ) <BR>&nbsp; { <BR>&nbsp;&nbsp; str =
+=3D L"int";=20
  <BR>&nbsp; } <BR>&nbsp; str.str.erase( str.begin() , str.end() ); =
<BR>&nbsp;=20
  str =3D L"int"; <BR><BR>i wrote this code against a button in dialog =
based=20
  application. Before <BR>clicking the button, the memory usage is 3MB =
and after=20
  this code it is 17MB <BR>although i believe it should have been back =
to 3MB=20
  after the statement <BR>str.erase( str.begin() , str.end() ). =
<BR><BR>My other=20
  observation is that if i exit the application in debug mode it =
<BR>tells=20
  almost everything about the memory leaks except for the file from =
which=20
  <BR>memory was allocated. I copied a code that would tell the file but =
it=20
  would <BR>all leaks are from crtdbg.h <BR><BR>anyone plz give me a =
solution to=20
  this.any help in this regard will be highly <BR>appreciated. <BR>P.S. =
I have=20
  been using Task Manager to see how much memory is bieng used by <BR>my =

  application. <BR>Regards <BR>Omar Javed</BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0092_01C491EB.2250F6D0--

0
ATField
9/3/2004 11:20:55 AM
Reply:

Similar Artilces: