Memory management

MRC & ARC

MRR (manual retain release) - manually claim and reliquish an object
retain
claim ownership of object
release
relinquish ownership of an object and destroy it immediately
autorealese
relinquish ownership of an object and defer its destruction later
Issues
MEMORY LEAK
When you forget to release an object
What's wrong: it's memory is never relinquished

DANGLING POINTER
When you try to release on object too many times
What's wrong: accessing invalid memory address
RETAIN CYCLE
When two different objects contain a strong reference to each other
ARC (automatic reference counting) - automatically claim and reliquish an object
You have to understand @property attributes, since they tell the compiler what kind of relationship objects should have.
strong
Creates an owning relationship
It makes sure the value exists as long as it's assigned to the property
weak
Creates a non-owning relationship
It prevents from retain cycle if one of two objects will be no longer needed

copy
Alternative to strong.
Instead of taking ownership of the existing object, it creates a copy of whatever you assign to the property, then takes ownership of that

Made on
Tilda