Autorelease Pool

Recently I work with uploading images from iOS to server, as the Apple Documentation for Autorelease Pool:

If you write a loop that creates many temporary objects.

You may use an autorelease pool block inside the loop to dispose of those objects before the next iteration. Using an autorelease pool block in the loop helps to reduce the maximum memory footprint of the application.

In my case, it allows user to upload multiple images (less than 10) to server and I tried implementing without autorelease pool but there is memory warning when users upload six photos from local album, it works well with autorelease pool.

The image quality taken with iPhone is better and better and size is larger and larger, if it uploads jpg images and usually uses UIImageJPEGRepresentation() to convert UIImage to NSData format which could be passed as parameter to server,  it’s so easy to use up memory in this process and use autorelease pool is a mandatory choice.

In a word, autorelease pool delays the call for release and release the object in the end of block automatically.


Apple Doc

What is autorelease pool? – Objective C

Objective-C: Why is autorelease (@autoreleasepool) still needed with ARC?

iOS autorelease pool blocks

Objective-C Autorelease Pool 的实现原理


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 iOS, IT, Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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