Jump to content
Navid Madani

TForm Destroys are not called when target is macOS ARM 64-bit

Recommended Posts

I have encountered a strange problem: Delphi Athens is running via Parallels on Apple Silicone. In the following demo, none of the destroyers are called when targeting macOS ARM 64, while everything works OK targeting Windows).  Also, I can get the Windows target to report the memory leak when I comment out fDebug.Free in FormDestroy, but not with macOS ARM 64.

Can anyone else reproduce this? Am I missing something?

Thanks!

 

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;

type
  TForm1 = class(TForm)
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    fDebug: TObject;
  public
    destructor Destroy; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

// TForm1.FormDestroy is not called when Target is macOS ARM 64-bit
procedure TForm1.FormDestroy(Sender: TObject);
begin
  ShowMessage('FormDestroy Called');
  fDebug.Free;
end;

// TForm1.Destroy is not called when Target is macOS ARM 64-bit
destructor TForm1.Destroy;
begin
  ShowMessage('Destroy Called');
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fDebug := TObject.Create;
end;

end.

 

Share this post


Link to post

It's not new : destroy of the main form and finalization bloc in units is not executed on Mac since years.

 

On Mac, for the main form use the onClose event instead of onDestroy.

Share this post


Link to post
16 hours ago, Patrick PREMARTIN said:

It's not new : destroy of the main form and finalization bloc in units is not executed on Mac since years.

 

On Mac, for the main form use the onClose event instead of onDestroy.

Is this the cross-platform development I keep reading about? 😎

Share this post


Link to post

I also stumbled upon this bug in one of my multi device apps when I tried to save data to a file within an OnDestroy event in a data module. Nothing was saved! The same problem in both macOS for Intel and macOS for ARM.


In reality, it’s even more serious. Neither OnDestroy nor destructors in forms or data modules are called when Mac apps are shut down! As a workaround, as mentioned earlier, you can place shutdown code in the main forms’ OnClose events. However, OnClose doesn’t exist in data modules, so in this case, the shutdown code must be called from the main form.


The problem is reported in RSP-26436, but only that the main form’s OnDestroy is not called. However, the issue is indeed worse. Unfortunately, QualityPortal is currently closed for new comments, but voting is still possible, so please vote to address this critical bug! 🙏

Share this post


Link to post
32 minutes ago, LGROX said:

The problem is reported in RSP-26436

You have not posted a link and probably it's a stupid question but how to find a RSP by number?

Share this post


Link to post
43 minutes ago, Cristian Peța said:

You have not posted a link and probably it's a stupid question but how to find a RSP by number?

1.) Log into https://quality.embarcadero.com/

2.) Enter RSP-26436 into search (you can find it at the upper right corner of the page) and you cannot copy paste it from the text above as it contains unicode characters.

 

https://quality.embarcadero.com/browse/RSP-26436

 

 

Edited by Lajos Juhász
it's right corner not left.
  • Thanks 1

Share this post


Link to post
3 minutes ago, Lajos Juhász said:

2.) Enter RSP-26436 into search (you can find it at the upper left corner of the page) and you cannot copy paste it from the text above as it contains unicode characters.

Finally... upper right corner (not left).... basic and advanced search doesn't work

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×