Differences between drain and release in use of NSAID utoreleasepool

Source: Internet
Author: User

Although the use of the NSAID utoreleasepool has changed a lot after the introduction of arc, it is necessary to understand the mechanism of the NSAID eleasepool:

NSAID utoreleasepool * Pool = [NSAID utoreleasepool alloc] init];

// Do something

After,

The difference between [pool drain] and [pool release:

ReleaseIn the reference counting environment, because the NSAID pool is a type that cannot be retain, the release will directly dealloc pool object. When the pool is dealloc, the pool sends a release message to all objects in the pool. If an object is autorelisted multiple times in the pool, each autorelease release of this object by the pool will be release. In the GC environment, release is a no-op operation (indicating that no operation is performed. It is a computer command that occupies a small amount of space but points out that no operation is performed ).

DrainIn the reference counting environment, it performs the same behavior as release. In the GC environment, this method calls objc_collect_if_needed to start GC.

Therefore, the focus is: In the GC environment, release is a no-op, so unless you do not want to start GC in the GC environment, you should use drain instead of using release to release the 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.