Citation: In most cases, this bug of MFC will not occur during simple use, that is, there will be no memory leakage. When will the cstring expose a bug?
My previous experiences with errors are: If you call a function with parameters referenced by cstring multiple times (such as funstr (cstring & Str ), at a certain time (related to the length of the string), the internal reference counter of the cstring is in disorder, resulting in Memory leakage.
It should be a "small problem" on the cstring package of vc6.0. The memory leakage problem of cstring is like a bomb, waiting for yourProgramWe know that we generally do not release the variables (objects) defined in this class when writing programs, even if some places tell us to use releasebuffer for release, but this does not solve the problem, because we have no way to apply for a variable space, so we often cannot solve the problem.
Memory leakage occurs today as follows:
I defined multiple cstring-type variables in the Form class, and then used DDX to exchange the variables. As a result, after the program runs successfully, I only need to debug the program and have memory leakage, it took a whole day to find a solution. (The first is not to say that I have used new. If I want to find it, I will clear it and I will not use new ).
In fact, the solution is always simple, that is, after updatedata (false), you can assign a value to the variable as null. The specific method is as follows:
Cstring m_xun;
M_xun = "";
M_xun.empty (); // This sentence is enough, and I have a lot of painful expressions.
// Fainted. There is no problem with the program running in debug, but there is a problem when exiting in release. Find it and assign a value to cstring.
The problem is being solved ....
After checking the cause at half past four, I finally found the cause. I will post another explanation.