Version: C Builder 5, 6
File: {C Builder Path} /clude/vcl/utilcls.h Line No .: 1039 (Implement Of Operator Ansistring () CONST) Number: 1065 (Implement of Operator WideString () CONST) Number: 1081 (IMPLEMENTION OF Operator wchar_t * () const) In the implementation of the above three operators, the resource (string) assigned by the variable V is not released, because V is the variable of TBasevariantt, and TBasevariantt has only constructor without Destructor, so V is allocated in the constructor The memory is lost. By simple experimental program, you can detect, write a COM Server program containing events, and the event interface function contains the parameters of the BSTR type. After registration, use Import Type library in C Builder, and generate the component of the package class. Then create a simple program, put the component of the package of Component on the FORM of the program, and implement the component's event function (can be empty code, but must have this function). such as:
Void __fastcall mainform :: myserverevent1 (BSTR MSG)
{
// EMPTY CODE
}
In the automatically generated packaging class, C Builder uses the automation interface to call each event function, from the source file, you can see the code that calls myServerevent1 is similar as follows:
IF (OnmyServerevent1)
OnmyServerevent1 (Tvariant (params [0]));
In this statement, I hiped the Operator Wchar_T * () Const, so the memory leaks happened. Let the server trigger the number of incidents, the memory leaks are obvious, and can always consume the light system memory. The solution is simple, slightly changed the code, don't forget to delete the pre-translated head file VCL60.csm (vcl50.csm) in the lib directory, otherwise the changed code will not be recompiled.
Although it is uncertain, it is likely to be able to recompile the VCL library because there may also be places where the above operators may also be called in the code in the VCL.