#1 Re: mORMot 1 » Access Violation when using mORMot 2 / DLL / Runtime packages » 2024-03-07 16:29:49

If anyone else has this problem: the error occurs in freeing memory for the dynamic array: SynVariantTypes. This array is created in mormot.core.variants initialization. It contains interfaced objects.
By default, the array and its objects are released when the application is closed via RTL finalization.
However, when using it in dll, an AV exception is generated.

The hack solution is to explicitly free the array before reaching the RTL.Finalization stage.

procedure FinalizeSynVariantTypes;
begin
  for var i: integer := 0 to length(SynVariantTypes) - 1 do
  TObject(SynVariantTypes[i]).Free;
  SetLength(SynVariantTypes, 0);
end;

For example, this procedure can be placed in the finalization part of another unit that uses mormot.core.variants (or mormot.core.log, which also includes this module)

Board footer

Powered by FluxBB