Objective C Memory Management

It uses Automatic Reference Count (ARC) discipline to manage memory for iOS projects, which means if you retain or copy an object and it will increase 1 for the count, otherwise it decrease 1 when relinquish the ownership by assign nil to the object, the object will be deallocated and memory will be completely free after reference count is 0.

We generally use weak for IBOutlets (UIViewController’s Childs). This works because the child object only needs to exist as long as the parent object does.

A weak reference is a reference that does not protect the referenced object from collection by a garbage collector.

Weak is essentially assign, a unretained property. Except the when the object is deallocated the weak pointer is automatically set to nil.



Objective-C ARC: strong vs retain and weak vs assign

To be continue …



About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application, iOS, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s