Dangerous NSAID utoreleasepool

Source: Internet
Author: User

The semi-automated memory management mechanism provided by the object-C does simplify maintenance.

The memory management mechanism implemented by Object-C is counter-based, similar to the object maintenance mechanism of COM. This management mechanism is highly efficient. Compared with Java and. Net's automated three-level memory management mechanism, automation is somewhat inferior, but performance and resource utilization are indeed incomparable. I personally think that it is a good option to automatically manage the memory version by referencing the counter in applications of different magnitude.

This is the background. There is a pool management region between the NSAID object and the release object. When the release object is released, the pool will automatically clear the memory declared on the stack in this region. Note that the system will automatically clean up the memory that is considered useless in this region without your own release. Generally, the basic type is initialized on the stack. We do not consider it. Because the object type is more of an operation unit, there is not much cross-scope reference, generally, there won't be too many problems. The problem is returned to the string type. The character types supported by Object-C include char, char [], char *, String, nsstring, nsmutablestring, Char, char [] is initialized on the stack without consideration. Other forms are encapsulation of char and initialized on the stack. Generally, the replication of pointer objects is considered to be shortest in terms of efficiency. It only pays an address pointer and does not actually copy data in the region. This creates a problem. The data will be cleared when the system deems that the original object is useless, and the new object is still pointing to the original location, now, operations on this object will have very serious consequences. Although we can use the retain mechanism to add 1 to the object reference counter, we cannot know exactly whether the system will automatically clean up when releasing, and it seems that the system will usually clean up at this time. It is dangerous to operate global string objects in this region.

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.