No memory leak ????
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.
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[].
You should be fine if you match the new[] with delete[].
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
Edited by - sQuid on February 21, 2002 7:38:07 PM
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
--
Eric
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement