iOS Memory Trivia

Source: Internet
Author: User

iOS has no garbage collection mechanism, OC has garbage collection mechanism, MAC has garbage collection mechanism, MAC is enabled after version 10.1
MRC (reference count) manually assign and release

Alloc Allocating space
Retain Introduction count plus 1
Copy replication (another space, same as the original)
Release released, reference count minus 1
Autorelease minus 1 At some point in the future.
Dealloc Clear

Problems in memory: memory overflow, wild pointer
GC: Garbage collection mechanism, can automatically determine that those memory is no longer used by the system to help us recycle
MRC: Manual memory management, also called Manual reference counting, is our own judgment that the memory is still in use, and how many people are using it. When the reference count is 0, the memory is freed and the pointer is empty, preventing the wild pointer
ARC: Automatic memory management, also called automatic reference counting, when we need reference count-1, the compiler helps us add the release statement
OC provides a garbage collection mechanism, but iOS does not use
Mac OS 10.8 uses a garbage collection mechanism before 10.8 is deprecated.



Some methods of reference counting
+alloc: Open memory, set reference count to 1.
-retain: Make reference count +1.
-copy: Assigns a copy of memory or an object and resets the copied memory or object reference count to 1.
-release: Make reference count-1.
-autorelease: Make reference count-1, but only after the auto-release pool is executed-1 operation
-dealloc: When the reference count is 0 o'clock, it is automatically called by the system to free up space
There are two forms of the auto-release pool: (First use preferred)
The first type: @autorelease {}
The second type: NSAutoreleasePool *pool=[[nsautoreleasepool alloc] init];
[Pool release];

When release has been released for 0 o'clock, it will cause excessive release.



iOS Memory Trivia

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.