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:
Himself to create the object that himself held
Objects that are not created by themselves can also hold
Release objects when you no longer need to hold objects yourself
Objects not owned by themselves cannot be freed
"0-1" OC Memory management