Sign up for FlowVella
Sign up with FacebookAlready have an account? Sign in now
By registering you are agreeing to our
Terms of Service
Loading Flow
Automatic Reference Counting (ARC)
Reference Cycles
One downside to ARC is the possibility of reference cycles. Suppose object A references object B, and object B references object A. There can be larger cycles (more than two nodes) as well.
Garbage collection approaches can handle reference cycles, though ARC cannot.
Weak References
Use weak references to indicate that an object is not the owner of the object it references. Weak references are not counted in the object's reference count.
ARC vs Garbage Collection
ARC works by keeping a count of how many references are held to a given object. Whenever a variable stops referencing the object, its reference count is decremented by 1. When an object's reference count is decremented to zero, it is no longer referenced and can be safely disposed of.
Contrast this with Java's garbage collection of periodic walking of the map of object references.