Infosys Interview Question

How do you manage memory in Swift, and how does ARC (Automatic Reference Counting) work?

Interview Answer

Anonymous

Feb 27, 2025

Swift uses ARC (Automatic Reference Counting) to manage memory. It tracks object references and automatically deallocates objects when no references remain. To avoid retain cycles, especially with closures and delegates, I use [weak self] or unowned. I also regularly check for leaks using Instruments and the Memory Graph Debugger to keep the app memory-efficient.