"0-1" OC Memory management

Source: Internet
Author: User
First, Memory management overview
  • Garbage collection Mechanism (GC): Memory is managed by the system, and programmers do not need to be managed.
  • Garbage collection in OC: Garbage collection is added to the OC2.0 version.
  • OC and IOS:OC have a garbage collection mechanism, but iOS masks this feature. Cause: iOS running on mobile devices, limited hardware resources (memory, power, heat control, etc.), and garbage collection mechanism has some drawbacks (in Java garbage collection mechanism, for example, its garbage collection is not when the program ends, the memory is immediately collected, but when the program needs memory, The memory is not recycled until the remaining memory is used by the program that is currently requesting memory. That is, OC has a garbage collection mechanism, the iOS platform masks the function of OC garbage collection, and Mac OS X has a GC.
  • Therefore, software development on the iOS platform requires the programmer to manage the memory.
Ii. Memory Management of iOS

Memory Management scope: Memory management is the memory of the heap area

iOS manages memory by reference counting . After iOS5.0, Xcode added arc (auto reference count), simplifying memory management.

Memory management on iOS is divided into MRC and arc. The difference is that MRC is used by programmers to manage memory by using reference counting, whereas arc is the system that automatically manages reference counts.

Principles of memory Management:

  1. Himself to create the object that himself held

  2. Objects that are not created by themselves can also hold

  3. Release objects when you no longer need to hold objects yourself

  4. Objects not owned by themselves cannot be freed

"0-1" OC Memory management

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.