5 quick tips for removing ARC in Delphi Sydney

With the release of version 10.4 Sydney, Delphi has officially moved away from the ARC memory model in the mobile compilers. This was announced in 2018, there is some nice background info in this blog post by Marco Cantu.

So how do you do a quick check if your Delphi mobile code has ARC dependencies you should fix?

Tip #1 – Run on Windows with ReportMemoryLeaksOnShutDown := True

This instructs the FastMM memory manager to report memory leaks. Simply run your iOS or Android App on Windows (with the Windows Platform active), perform the usual actions an end-user would perform and close the application. Any memory leaks will be reported and should be fixed.

In your application source code add this line:

  ReportMemoryLeaksOnShutdown := True;
  Application.CreateForm(TFormMain, FormMain);

If you have a memory leak a message like this will popup after closing the application.

Unexpected Memory Leak

Tip #2 –  Search | Find In Files (Shift-Ctrl-F) for any “.Create” code

Most ARC (Automatic reference Counting) code should be changed to CTFF (Create Try Finally Free). Just check if there is a try-finally and a free directly after the .Create. Not all Create code needs a try-finally-free, as some instances are owned by their container, for instance in a TObjectList<T> that may take ownership of the instantiated object.

Change this ARC code

procedure DoSpellCheck;
  Harry: TWizard;
  Harry := TWizard.Create; 

To this CTFF code

procedure DoSpellCheck; 
  Harry: TWizard; 
  Harry := TWizard.Create;

Some code can not be easily changed from ARC to CTFF, mostly due to the Free needing to be called at some unspecified time in the future, which for instance is common in multi-threaded code. If this applies to you then you could take a look at smart pointers in Spring4D using Shared.Make(TObject.Create), or take a look at the new custom managed records which where introduced in Delphi 10.4. Both options enable you to use ARC style freeing of resources, within the now default unified memory model.

Tip #3 – Use a tool to check for memory leaks

The code in tip #1 uses the built-in FastMM4 and is free. There is also a dual-license newer version FastMM5, both are however limited to Windows. Luckily there is a nice and simple free library called leakcheck that does this for all Delphi platforms. Alternatively, if detecting leaks in Windows only is preferred, the commercial DeLeaker has a lot of options and easy overview of memory leaks. A nice summary of these tools and more can be found in the blog post of Wagner Landgraf.

Tip #4 – Check for platform specific code

The short check for memory leaks under the Windows platform will skip platform specific code for Android and iOS, so you should check for compiler directive based platform dependencies {$IFDEF ANDROID}, {$IFDEF IOS}, but also for run-time dependencies like with TOSVersion.TPlatform.pfiOS and TOSVersion.TPlatform.pfAndroid. Note that the compiler directive AUTOREFCOUNT has been removed in Delphi 10.4, but its entirely possible you used this in your own code to check for ARC availablity.

Tip 5 – Check for weak references

These are mostly introduced to enable multiple references to instances without affecting reference count in combination with ARC. Do not just remove them, they can also be used for other reference counted data structures which may not have anything to do with ARC perse.

Even without ARC, reference counting still exists in Delphi. The compiler will still automagically reference count interfaces and strings. The same mechanism is also used for the new custom managed records.

RAD Studio 10.4 Sydney Webinar 16 juni 2020

View of Sydney Harbour

Barnsten organiseert een RAD Studio 10.4 webinar op 16 juni om 14:00 waarbij ik de mogelijkheid krijg om enkele van de nieuwe features van Delphi 10.4 wat uitgebreider te laten zien. Nu ben ik best blij met de nieuwe versie dus die kans laat ik niet voorbij gaan.

Onderwerpen zijn  de werking en voordelen van per control VCL Styling, het hoe en wat van de nieuwe Delphi Language Server Protocol server voor Code Insight en de ins en outs van Managed Records en het uitfaseren van ARC (Automatic Reference Counting) op de mobile platforms. Er zit nog wel meer in qua onderwerpen, maar die kom je vanzelf tegen als je het webinar volgt.

Meer info en inschrijven kan met deze link::

Ontdek RAD Studio 10.4 Sydney – Webinar 16 juni – 14.00 uur

Tot volgende week dinsdag bij de Q&A !

Delphi 10 Parallel Programming Training – 10 en 11 juni 2020 (verplaatst)

Altijd al willen weten hoe je al die CPU cores voor je kunt laten werken in Delphi?

In deze twee daagse training gaan we gebruik maken van de System.Threading bibliotheek in Delphi, ook wel de PPL, Parallel Programming Library genoemd.

We starten eenvoudig met TTask en TFuture en TParallel.For en breiden dan uit naar hoe je dit eenvoudig, robuust en zonder dead locks toepast in je database verbindingen, communicatie met webservices en andere taken die je asynchroon wilt uitvoeren.

Maak je applicatie meer responsive en gebruik die cores!

De training is ingepland voor 10 en 11 juni bij het jachthuis te Doorn (nabij Utrecht).
Dit event is verplaatst in verband met het corona virus en wordt later opnieuw ingepland.


Coderage 2018 – Building Microservices and Progressive Web Apps (PWA) with Delphi

Thank you for attending my Coderage 2018 session on Building Microservices and Progressive Web Apps (PWA) with Delphi and TMS WebCore.

If you want to replay the session, please visit the Coderage 2018 page on Embarcadero Academy.

Please find the download with source and slides here:
Download source and slides
The download has been compressed with RAR with password coderage2018
and has the following SHA-256 checksum

Have fun creating your own REST microservices and PWA‘s!

Note: with newer versons of TMS WebCore you may need to change two lines of code in the file UnitJSONHelper.pas.

Weblib.REST, Weblib.JSON;

lArray := lJSONObject.GetJSONValue('result');

Additionally the no longer needed WebRunner lines in the Project file TheCounterWeb.dpr should be automatically removed when you open the project, if not remove them manually.

CodeRage 2018 – 4-6 December 2018

CodeRage 2018 is just around the corner!



The complete schedule:

This CodeRage I’m showing you how to build microservices and how to consume them from desktop, Android mobile and using a HTML / JavaScript web app. The web app uses TMS WebCore and PAS2JS, but goes beyond basic coding as it also shows you how to convert the web app to a Progressive Web App, or PWA for short

The boilerplate code is of course available for download, please use it to jump start your own software.

Oh, and the nice thing about PWA, an Android device will offer the user the option to install the web app as an actual app with an icon on the start screen. Good stuff!

Register here, it’s free but infinite value for money:

Delphi Meetup Web Development bij TMS op 12 juni 2018

Het is al bijna zover, de volgende Delphi Meetup. Dit keer in Wevelgem op het kantoor van TMS Software.

Bruno Fierens laat zien hoe je vanuit de Delphi IDE, met de Delphi taal en componenten, op een een RAD manier web user-interfaces kunt bouwen. Ook zie je hoe vanuit die Delphi web applicaties op eenvoudig bestaande Javascript libraries, zoals bijvoorbeeld jQuery, gebruik kan worden gemaakt van user-interface controls. Als laatste laat hij zien hoe dit samen met Delphi databinding te gebruiken is..

In aansluiting op de sessie van Bruno combineert Danny Wind in een use case een aantal technologieën om je te laten zien hoe eenvoudig het is om gebruik te maken van RADical Web. Danny zal een op REST gebaseerde micro-service back-end gebruiken en een  front-end die zowel RADical Web als Apps (Android/iOS) gebruikt. En dit alles gewoon met Delphi Code!

Meer info vindt je hier:

Get your App in the Google Play store before August 1, 2018

Google is changing its requirements for the target SDK API level. Starting from August 1st any new app uploaded to the Play Store must target API level 26 (Android 8.0). If you have an existing app in the Play Store you’ll have some more time, as updates to the app must only meet this same requirement on November 1st.

This means that if you are currently developing a new Delphi Android App you should consider uploading it into the Play Store before August 1st. Why? The current version of Delphi uses a target SDK of API level 14. If you upload your new app now, this buys you some time until November 1st to become API level 26 compliant with an app update.

I’m working on an API level 26 issue right now, where I’m extending the JContext of Delphi with some of the new API level 26 features for starting a foreground service. This is needed to comply with the new background execution limits introduced in Oreo. This works quite well, and does not require a lot of code.

If you can not upload your app to the Play Store before August 1st, then this blog post from Dave at Delphi Worlds may help you further. It changes some of the Delphi code to achieve (partial) API level 26 compliance.

Delphi 10 Tokyo Update and Firemonkey-Android Power training March-2018

On March 8th and 9th we have the Delphi 10 Tokyo Firemonkey and Android Power training planned in Etten-Leur in the Netherlands. In just two days you will learn how to develop an Android App in Delphi, with high level features in the GUI down to high tech stuff when interacting with the Java side. This training is available in both English and Dutch. Registration can be found here.

A week after, on March 15th and 16th, we have the Delphi 10 Tokyo Update training in our agenda. As one of the previous attendees told me a couple of weeks after attending this training “I’ve learned so many new things in these two days; I especially liked the (PPL) TTasks chapter”. This one is only available in Dutch, registration can be found here. Note: due to a conflict in planning with an on-site training this open training has been moved to April 19th and 20th.

Delphi “The LAB” – 19 september 2017

Er komt een mooi evenement aan met de prachtige gelegenheid om rustig te spreken met de presenters van het evenement in “The LAB”.

Neem de tijd om bij een kopje koffie te praten met elk van de presenters in het restaurant van het Evoluon, maar volg ook de interessante sessies van sprekers als Jens Fudge, Andrea Magni, Bob Swart en David Millington. Vergeet ook de CurieWise C++ Builder sessie van Ludo Stroetenga niet.

Mijn sessie op dit seminar gaat over het oppeppen van bestaande Delphi VCL applicaties. Verplaats de gehate zandloper naar TTasks, poets je User Interface op met fraaie controls en gebruik enkele nieuwe technieken om je code indrukwekkend sneller te maken. In “The LAB” heb je ook nog eens uitgebreid de tijd om me vragen te stellen over het gebruik van TTask, User Interfaces of over het maken van een goede espresso.

The LAB, where you get to spend time with Delphi presenters


PDF met de sessies:

Inschrijven kan hier:

Delphi in het onderwijs – 20 april 2017

Als u als leraar kennis wilt maken met de mogelijkheden van Delphi als programmeertaal in het voortgezet onderwijs dan kan dit nu op de Slim bijeenkomst op 20 april 2017, deelname is gratis, de locatie is het SLB diensten kantoor te Amsterdam.

In deze bijeenkomst laat ik samen met Barnsten zien waarom Delphi voor leerlingen de beste taal is om te leren programmeren.

  1. Delphi is Pascal, en Pascal is gemaakt om te leren programmeren
  2. Delphi kent een lineaire leercurve, vanaf uur 1 maak je al je eerste eigen applicatie
  3. Delphi bestrijkt het hele spectrum van low-level CPU tot aan high-level classes en frameworks
  4. Delphi applicaties compileer je naar alle platformen, Windows, Mac (OSX), iPhone (iOS), Smartphones (Android) en web servers (Linux)
  5. Delphi spreekt de jonge developer aan met Apps op de Android SmartPhone en met IoT communicatie met gadgets

Meer informatie over de locatie en inschrijving vindt u hier: