Junior — Middle
When is memory released occupied by an object?
sobes.tech AI
Answer from AI
In iOS, memory is freed when the reference count (retain count) of an object reaches zero. This means that no one is referencing the object anymore, and the system can release the memory it occupies.
Modern applications use ARC (Automatic Reference Counting), which automatically increases and decreases the reference count when assigning and removing references to an object.
Example:
class MyClass {}
var obj: MyClass? = MyClass() // reference count = 1
obj = nil // reference count = 0, object is released
Thus, memory is freed immediately after the last owner stops referencing the object.