How ARC work in swift
Before start with example I would like to share the some method where by calling them on instance, the retain count of instance increase or decrease.

I will show you an example of automatic reference count work.
Here example starts with the class Owner.
Which have a stored property i.e name.
The next code snippet defines three variables of type Owner?


You have created a new Owner instance and assign it to the owner1 variable:


Now New Owner instance has been assigned to the owner1 variable, there is now a strong reference from owner1 to the new Owner instance. So instance reference count will be 1.
If you assign the same Owner instance to two more variables i.e owner2, owner3. There are two more strong references to that owner instance are established:


There are now three strong references to this single Owner instance.
If you want to deallocate the Owner instance we need to remove this strong reference to an instance.




Note: When instance reference count reached to zero then that instance will deallocate from the memory.
ARC golden rules
- All global objects should be autorelease.
- All singleton objects should be autorelease.
- When object is used massively throughtout the app we make that object autorelase.
- When same type of object come in memory in large quantity we use autorelase.
- ARC run at compile time.
In next artical we will discuss the scenario where ARC fail and use manual memory management.
https://medium.com/@shantakokateit/retain-cycle-in-swift-d91dcb441419