Delphi: ARC and Objective-C wrapped objects – how to release?


In Delphi/FMX there is no ARC for the Objective-C objects represented by the import wrapper classes and interfaces.

When dealing with Objective-C objects you’ll have to call retain and
release yourself at the correct points. Allocating a new Objective-C
object will initialize its reference count to 1 and calling release
will drop it to 0 thus destroying it.

For example, i want to create a UILabel dynamically. According to the reference above, my code should be look like this (I’m assuming that I have chosen the positions for retail and release correctly):

procedure TForm1.Button1Click(Sender: TObject);
lbl: UILabel;
lbl := TUILabel.Wrap(TUILabel.alloc.init);


It does not work. What is the right way to release wrapped Objective-C objects in Delphi/FMX?

With “It doesn’t works” I mean that the UILabel is not released as expected ans still allocates the memory. I found this with the help of the Xcode Allocation Instrument.

Comments are closed.