As I know , Garbage collection is not enabled by default in Cocoa and should be selected in Build setting. But in build setting I just can see automatic reference counting. What am I missing?
As I know , Garbage collection is not enabled by default in Cocoa and
Share
Apple have deprecated Garbage Collection. You should use ARC instead. You can find ARC documentation here. There is a WWDC talk about ARC here
When you use ARC, objects are reference counted rather than garbage collected. However you are not expected to call
retainorrelease/autorelease. The compiler inserts calls toretainorrelease/autoreleaseon your behalf. In practice, this works similarly to garbage collection. You must be careful to avoid reference cycles which can prevent the reference count of objects becoming zero and preventing the objects from being dealloced. This mostly is introduced by parent/child relationships when a child holds a reference to it’s parent as happens in most instances involving delegates.Reference cycles can be avoided by marking one of the references in the parent/child relationship as weak. Properties marked as weak create a weak reference to an object. Weak references to an object are set to
nilwhen the reference count of an object becomes zero.The talk I mentioned above goes into further details.