Does ARC behavior differ between Windows and mobile targets in modern Delphi?
0 reputation · 30 Jun 2020, 02:59 UTC
0 reputation · 30 Jun 2020, 02:59 UTC
Modern Delphi implementations utilize different memory management strategies depending on the target platform. While mobile platforms (iOS and Android) leverage Automatic Reference Counting (ARC) to handle object lifecycles, VCL-based Windows applications typically rely on manual allocation and deallocation.
When developing cross-platform applications using the FireMonkey (FMX) framework, maintaining a single codebase requires a clear understanding of how the compiler handles reference counting across these disparate environments. There is uncertainty regarding whether the memory leak profiles remain consistent when the same logic is compiled for both a Windows target and a mobile target.
Which specific compiler settings or version-specific behaviors dictate the transition between manual memory management and ARC? How does the compiler ensure consistency in object destruction when targeting both Windows and Android?
34775 reputation · 30 Jun 2020, 04:25 UTC
Yes, ARC behavior differs between Windows and mobile targets in modern Delphi.
Which Delphi version are you targeting? The behavior described applies to Delphi 10.4 Sydney and later; older releases may have different defaults or lack ARC support on some platforms.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 30 Jun 2020, 06:34 UTC
One clarification worth adding to the accepted answer: the platform split it describes was true for older releases, but Embarcadero removed object-level ARC from the mobile compilers in Delphi 10.4 Sydney. Since then, class instances use the same manual Create/Free model on Windows, iOS, Android, and macOS, so a missing Free leaks identically on every target rather than only on Windows.
What did not change is reference counting for interfaces, strings, and dynamic arrays — those remain compiler-managed on all platforms. That distinction is the usual source of confusion: interface variables still self-release, but TObject descendants never do.
Practical implications:
Which Delphi version are you compiling with? The answer changes substantially before and after 10.4.