You are not logged in.
I am using Delphi 11 and latest mORMot2. When closing an application I have a memory leak pointing to mormot.core.variants. The exception is almost the same as in this topic: Memory leak starting rev. 179, with the exception of TObject.DisposeOf being called last in the call stack.
But, we have a proprietary/custom made plugin framework (host application is loading bpl's at the runtime) and this memory leak is happening only when using this framework inside a bpl loaded by the host and not when using mormot.core.variants directly in the host. Given this situation I did my own analysis and made a fix for which I need your opinion.
Problem seems to be in the SynVariantTypes array and "my fix" was to simply add the DeInitializeUnit at the end of mormot.core.variants:
procedure DeInitializeUnit;
var
i: integer;
begin
SynVariantTypesSafe.Lock;
try
for i := 0 to length(SynVariantTypes) - 1 do
begin
SynVariantTypes[i].Free;
end;
finally
SynVariantTypesSafe.UnLock;
end;
end;
initialization
InitializeUnit;
finalization
DeInitializeUnit;
Is it OK to do it like this? Am I making some huge mistake by doing it like this? Would it harm to have this code in the official release of mORMot2 so I don't have to patch it every time we update the library?
Thanks,
+adnan
Offline
My guess this is a Delphi RTL problem.
The SynVariantTypes[] are just an additional (faster) list around the existing custom variant type registration system.
In fact, the TCustomVariantType.Create constructor calls RegisterCustomVariantType() from the variants unit to register the class instance to its internal LVarTypes[] list, and the finalization of the variants unit releases the instances in the ClearVariantTypeList local procedure.
My guess is that the finalization is not properly called for packages, for whatever reason.
I was not able to find any relevant RSP on the Embacardero website - my login don't fit any more. Perhaps they are still down / in management state.
Since I don't use packages (nor Delphi in fact), perhaps could you investigate a little more and try to debug what happens when the package is released?
Offline
Thanks Arnaud for your valuable response.
I have tried to implement a package using mormot.core.variants and a VCL application using this package dynamically. Everything works as expected without my changes to the mormot.core.variants. Difficult to blame Delphi RTL for a problem in this case given that we are using a custom/proprietary plugin framework. I simply need to put more effort into debugging if this framework does something out of ordinary.
Offline