iOS Auto-free pool

Source: Internet
Author: User

The auto-free pool is implemented as a stack: When you create a new auto-free pool, it is added to the top of the stack. The object that receives the Autorelease message is placed in the topmost auto-free pool. If you put an object into an auto-free pool and then create a new auto-free pool and then destroy the newly created auto-free pool, the auto-free object will still exist because the auto-free pool that holds the object still exists.

What is an auto-free pool

1. Autorelease Pool

The Autorelease pool is an automatic memory recovery mechanism for OC, which can release some temporary variables through the automatic release pools recovery. Automatically release the pool when it's destroyed, all the objects in the pool do a release operation.

2, Autorelease

Any OC object that calls the Autorelease method will place the object in its closest auto-release pool (the release pool at the top of the stack).

How to create an auto-free pool

ios5.0 New Way

@autoreleasepool {}

The old way before ios5.0

NSAutoreleasePool *pool=[[nsautoreleasepool Alloc]init]; [Pool release];

The auto-free pool is implemented as a stack: When you create a new auto-free pool, it is added to the top of the stack. The object that receives the Autorelease message is placed in the topmost auto-free pool. If you put an object into an auto-free pool and then create a new auto-free pool and then destroy the newly created auto-free pool, the auto-free object will still exist because the auto-free pool that holds the object still exists.

Top
0

iOS Auto-free pool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.