Search code examples
c++mfcc-stringsgetbuffer

What if I don't call ReleaseBuffer after GetBuffer?


From CString to char*, ReleaseBuffer() must be used after GetBuffer(). But why? What will happen if I don't use ReleaseBuffer() after GetBuffer()?

Can somebody show me an example? Thanks.


Solution

  • I'm not sure that this will cause a memory leak, but you must call ReleaseBuffer to ensure that the private members of CString are updated. For example, ReleaseBuffer will update the length field of the CString by looking for the terminating null character.