[0, 2
I. Memory Management Overview
- Garbage collection mechanism (GC): memory is managed by the system, which is not required by programmers.
- Garbage collection in OC: add garbage collection in OC2.0.
- OC and iOS: OC have a garbage collection mechanism, but iOS shields this function. Cause: iOS is running on mobile devices, with limited hardware resources (memory, power, heat control, etc.), and the garbage collection mechanism has some drawbacks (taking java's garbage collection mechanism as an example, its garbage collection does not recycle memory immediately after the program ends. Instead, it recycles memory only when the program requires memory and the remaining memory is not used by the program currently applying for memory ). That is, OC has a garbage collection mechanism. The iOS platform shields OC garbage collection, while Mac OS x has GC.
- Therefore, developers need to manage the memory for software development on the iOS platform.
2. iOS Memory Management
Memory Management scope: Memory Management manages the heap memory.
Through iOSReference countMemory Management. After iOS5.0, Xcode added ARC (automatic reference count) to simplify memory management.
Memory Management Methods on iOS are divided into MRC and ARC. The difference between the two is that MRC uses reference counting by programmers to manage memory, while ARC manages reference counting automatically by the system.
Memory Management Principles: