Objective-c nsaid utoreleasepool in iPhone

Source: Internet
Author: User

 

 

1. NSAID utoreleasepool is actually an automatic processor of object reference count. The NSAID utoreleasepool can have multiple nodes at the same time, and its organization is a stack. There is always a stack top pool, that is, the current pool. Every time a pool is created, one pool is pressed into the stack, change the current pool to the new pool. Then, each time a drain message is sent to the pool, the pool at the top of the stack pops up, and change the current pool to the next pool in the stack.

 

2. In the main function of the program entry, the NSAID pool is called. This ensures that the program does not call the NSAID pool, but is automatically released upon exit. It is best to implement NSAID utoreleasepool for new threads

 

3. The management scope of the NSAID utoreleasepool is the object between the NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init]; and [pool release ];

 

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

When the [pool autorelease] is executed, the system releases the autorelease object once again. If there is no NSAID utoreleasepool, the memory will not be released.

Note: The object is not automatically added to the current pool, but needs to send the autorelease message to the object. In this way, the object is added to the management of the current pool. When the current pool receives a drain message, it simply sends a release message to all objects it manages.

 

For example

 

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

 

Nsstring * nsstring;

Char * cstring = "Hello cstring ";

Nsstring = [nsstring stringwithuf8string: cstring];

 

[Pool release];

 

 

 

5. The alloc object must be displayed and released.

 

For example:

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

 

Nsstring * string = [[nsstring alloc] init];

[String stringbyappendingstring: @ "Hello world! "];

 

[Pool release];

[Nsstring release];

 

 

Related Article

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.