Junior — Middle
Mis juhtub objektiga mälus, kui sellele enam aktiivseid viiteid ei ole?
sobes.tech AI
Vastus AI-lt
If an object in memory in iOS no longer has active references (i.e., the reference count has reached zero), the system automatically frees the memory occupied by that object. This is achieved through the automatic memory management mechanism — ARC (Automatic Reference Counting).
Example:
class MyClass {}
var obj: MyClass? = MyClass() // reference count = 1
obj = nil // reference count = 0, object is released from memory
Thus, when the object becomes inaccessible, ARC removes it, preventing memory leaks.