PRB: CString::ReleaseBuffer() Does Not Release Extra Memory (114201)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q114201 SYMPTOMS
When CString::ReleaseBuffer is called and the length of the string is less
than the allocated buffer length, the extra bytes are not released. This
just means that your program might end up maintaining more memory than
absolutely necessary. This will not cause a memory leak. All of the memory
will be freed when the CString object is destroyed.
CAUSE
The behavior of CString::ReleaseBuffer described above is by design.
RESOLUTION
Visual C++ 2.0 and later include CString::FreeExtra to release any unused
memory.
In earlier versions, one way to make the string's buffer length equal to
the string's data length is to write a function which will free the extra
memory. The two functions in the sample code section demonstrate two
different methods of writing this function; either as a member function of
a derived CString class or as a separate function which accepts a CString
parameter type. Note that if the member function approach is taken, then
the derived class will need to override the constructors provided by the
CString class in order to have access to them.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbBug kbprb kbVC500fix KB114201 |
---|
|