
How to trace problem Memory leak ?
I don't know if it is related to your memory leak, but I'll explain the
difference between parameter "CString" and parameter "const CString &".
When the parameter is CString, the CString copy constructor is called, and a new,
temporary CString object is created for the duration of the function call, but
with the same text as the argument passed in. In this case, you can call the
function with any expression that a CString constructor can accept, including a
constant string expression. If a CString is used when calling the function, the
buffer is reused for the sake of efficiency, and the reference count is increased
until the function ends. If you modify the parameter, the buffer is copied to
avoid changing the original.
When the parameter is "const CString &", a copy is not made. The argument passed
in must be a real CString object, because it will be used directly. The
reference count is not increased. Since it is a constant parameter, it cannot be
modified in the body of the function. Because the original is used without making
a copy, this type of function call is a bit faster.