FastMM4 icon indicating copy to clipboard operation
FastMM4 copied to clipboard

D 10.1 Berlin: crash with empty FMX application

Open tueddy opened this issue 8 years ago • 11 comments

Hello,

using FastMM4 in an empty FMX application in Delphi 10.1 Berlin results in crash in procedure TMonitor.Destroy;

steps to reproduce:

  • new empty FMX application, target Win32
  • Add FastMM4 as first unit in dpr file
  • After closing see some FMX memory leaks
  • Crash in system.pas

crash

Best regards Dirk

tueddy avatar Apr 28 '16 15:04 tueddy

I just quickly analyzed the issue and it is caused by the fact that the weak references hashmap is lazy initialized which happens when FastMM is already initialized but is finalized in the finalization part of System.pas which happens after the finalization part of FastMM4.pas is run (which calls FinalizeMemoryManager).

So this requires finalizing FastMM later (or not at all as seems to be done for BCB according to the ifdef?) or using the NeverUninstall option?

sglienke avatar Jul 05 '16 16:07 sglienke

Wow, how did something that basic make it past both internal testing and the beta?!?

masonwheeler avatar Aug 24 '16 18:08 masonwheeler

Is it the same as www.translate.ru -> http://www.sql.ru/forum/1162994/grabli-s-fastmm-bds-exe ?

They say to avoid this it needs to ensure the memory manager does not hook into SysUtils neither directly nor via other used units.

the-Arioch avatar Aug 24 '16 19:08 the-Arioch

From that forum "That is the same: Monitors support is initialized in SysUtils themselves"

the-Arioch avatar Aug 25 '16 09:08 the-Arioch

Quality Central: https://quality.embarcadero.com/browse/RSP-16796

GunSmoker avatar Jan 31 '17 08:01 GunSmoker

The Quality Central issue says it is resolved in 10.2.2 but has any of you actually checked that it is? I'm asking because I'm currently using 10.2.3, which should contain the fix, and yet, I'm observing the same error message (operation detected after uninstalled) at the end of my VCL application...

obones avatar Nov 20 '18 14:11 obones

Well, ok, sorry for the noise, this comes from my own code, a very weird case of interdependencies between interface instances.

obones avatar Nov 20 '18 15:11 obones

I've got the same issue using Tokyo 10.2. I'll see if my client will allow me to upgrade to 10.2.2 or 10.2.3 and see if that fixes the issue.

[edit] OK, I can confirm I'm on 10.2.2 and the issue still exists here on my environment. So no, the issue doesn't seem to be resolved.

graemeg avatar Dec 13 '18 18:12 graemeg

Hi,

A somewhat hack (but seems effective) fix for this Makes the finalize routines run later (from the ExitProcessProc routine).

Regards Roger

Change the bottom of FastMM4.pas (including initialize and finalize) with code below. Add a section to the FastMM4Options.inc file.

// FastMM4Options.inc { Enable UseExitProcFinalize to cause late shutdown of the memory manager Good for newer versions of delphi (10.1+), esp with fmx} {$define UseExitProcFinalize}

// FastMM4.pas

{$ifndef PatchBCBTerminate} {$ifdef UseExitProcFinalize} var oldExitProc: procedure();

procedure ExitProcFinalize; begin FinalizeMemoryManager; if assigned(oldExitProc) then oldExitProc; end; {$endif} {$endif}

initialization RunInitializationCode;

finalization {$ifndef PatchBCBTerminate} {$ifdef UseExitProcFinalize} oldExitProc := ExitProcessProc; ExitProcessProc := ExitProcFinalize; {$else} FinalizeMemoryManager; {$endif} {$endif}

end.

rplant09485 avatar Oct 23 '19 22:10 rplant09485

While it says that the issue is fixed in 10.2.2 - it is not. Not all FreeMem/Dispose calls were removed in 10.2 and 10.3. Only 10.4 seems to fix this issue completely.

GunSmoker avatar Oct 21 '20 15:10 GunSmoker

This is fixed in 10.4, so this ticket should probably be closed.

GunSmoker avatar Oct 28 '20 17:10 GunSmoker