CString pStr = new CString;
I have found thatthe AllocBuffer function in the CString
class does not get called when using the new command but
it does when you do:
CString cStr;
This is a bug and I have not been able to fix it. How do I
get MS aware of this problem and get them to fix it?
Michael De Blasio
HTH
wardo
"Michael De Blasio" <debl...@saic.com> wrote in message
news:043101c0f982$b4ff7880$9be62ecf@tkmsftngxa03...
Jim
"Michael De Blasio" <debl...@saic.com> wrote in message
news:043101c0f982$b4ff7880$9be62ecf@tkmsftngxa03...
However, if I assume you made a typo and meant to write the above,
there is still not an issue. The destructor of the string will free
the buffer. This means that if you do a new you *must* do a delete.
Can you say more about what you are doing with the string? Note that
if you are putting the CString * into the itemdata of a listbox,
nothing will free it up; you need to have an owner-draw listbox and
implement an OnDeleteItem handler. If you are storing it in a class,
the class is responsible for deleting the string in its destructor.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
I now have more information on this problem. The memory
leak occurrs when I dynamically allocate CString that are
then placed into a CStringList. Here is a code sample that
produces the problem.
int iMaxListSize = 3;
CStringList docList;
CString *pStr, *pStr1, *pStr2;
POSITION pos;
for ( long i = 0; i < 100000; i++ )
{ if ( docList.GetCount() >= iMaxListSize )
{ pos = docList.GetHeadPosition();
pStr1 = (CString *) &docList.GetAt(pos);
// CString is also destroyed by RemvoeHead()
pStr2 = (CString *) &docList.RemoveHead();
ASSERT ( pStr1 == pStr2 );// verify what was in
the head
}
pStr = new CString(_T("This is a test."));
POSITION pos = docList.AddTail((const CString&) *pStr);
ASSERT( pos != NULL );
}
docList.RemoveAll();
Michael De Blasio
You do a lot of "new" but no deletes... that's where the leak is...
HTH,wardo
"Michael De Blasio" <debl...@saic.com> wrote in message
news:0ff101c0fa4e$ca2e29f0$9be62ecf@tkmsftngxa03...
Joseph M. Newcomer [MVP]
The following is my page showing samples of CStringList but it does not say
much more.
http://www.cpp.atfreeweb.com/Collections/CStringList.html
"wardo" <wa...@provisionconsulting.com> wrote in message
news:AvmY6.20636$9r1.1...@e3500-atl1.usenetserver.com...
"Sam Hobbs" <sam...@socal.rr.com> wrote in message
news:uKJwrC3#AHA.408@tkmsftngp03...
CString RemoveHead();
CString RemoveTail();
"wardo" <wa...@provisionconsulting.com> wrote in message
news:mRsZ6.31936$9r1.2...@e3500-atl1.usenetserver.com...