What if I don't call ReleaseBuffer after GetBuffer?

Landy picture Landy · Feb 26, 2010 · Viewed 8.9k times · Source

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.

Answer

Nick Meyer picture Nick Meyer · Feb 26, 2010

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.