Archived

This topic is now archived and is closed to further replies.

mrandrew

No memory leak ????

Recommended Posts

I have a class CD3DStatic, as the constructor parameter it takes a LPCTSTR, allocates new array of TCHAR''s (m_szText = new TCHAR[_dwStrLength], the m_szText is LPTSTR) and copies the string. In the destructor I free it by calling the delete[] m_szText;. When run the MSVC 6.0 shows a dialog Debug Error - Damage after normal block(#55) at 0x... I tried also just delete, but as I expected it didn''t help. Also the strange thing is that the MSVC doesn''t detect any memory leaks if I don''t delete it in the destructor.

Share this post


Link to post
Share on other sites
Likely the problem is a memory overwrite. Are you certain that you are not writing over the end of the allocated memory? Putting too many characters into the array?

You should be fine if you match the new[] with delete[].

Share this post


Link to post
Share on other sites
As was mentioned in a recent thread whenever you design a class with a non-trivial destructor that does something like a delete[] you need to provide a copy constructor and an assignment constructor for the class. Have you got these?

Edited by - sQuid on February 21, 2002 7:38:07 PM

Share this post


Link to post
Share on other sites
Sounds like you''ve neglected to allocate space for the null byte on the end of the string. Make sure you allocate _tcslen( szText ) + 1 characters.

--
Eric

Share this post


Link to post
Share on other sites