Delphi Firemonkey: how to find all references to a Form under ARC?


I know about DisposeOf (described in many places including this SO answer) to free the Form, but consider it as a hack. From what I understand it puts the object in Zombie state and might not completely remove it from memory.

The correct way would be to identify and remove all references to the Form. However trying to do this, there is one reference I cannot find.
Here is my code:

var MyForm: TMyForm;

//Dynamically create the form
MyForm := TMyForm.Create(Application)

//Destroy the form to free up memory
Application.RemoveComponent(MyForm);//reduces RefCount from 4 to 2
if MyForm.RefCount=1 then //RefCount is 2 here
MyForm := nil
ShowMessage(‘Cannot release MyForm: RefCount=’+inttostr(MyForm.RefCount));

I use Delphi 10 Seattle and target the iPad with iOS 9.0.

Where do I find the last reference to the form?

Comments are closed.