YouTip LogoYouTip

Ios Memory

# iOS Memory Management * * * ## Introduction The basic idea of memory management under iOS is reference counting, which controls the life cycle of memory objects by the reference count of objects. Specifically, there are mainly two ways in programming: 1: MRR (Manual Retain-Release), manual reference counting, the creation, destruction, and changes in the reference count of objects are all done by developers. 2: ARC (Automatic Reference Counting), automatic reference counting, which only takes care of object creation, and other processes no longer require developers to worry about their destruction. It is similar to garbage collection, but it is actually reference counting. ### Problems Faced According to Apple's documentation, the two main problems faced are: Data that has been released or overwritten is still being used. This will cause memory damage, usually leading to application crashes, or worse, damaging user data. Not releasing data that is no longer used leads to memory leaks. The allocated memory is not released, even if it is never used again. Leaks can cause the application's memory usage to increase continuously, which in turn may lead to poor system performance or a crash. ### Memory Management Rules We create our own objects, and when they are no longer needed, we release them. Retain the objects that we need to use. Do not release these objects if it is not necessary. Do not release objects that we do not own. ### Using Memory Management Tools You can analyze memory usage with the help of Xcode tools instruments. It includes tools such as the Activity Monitor, Allocation, Leaks, Zombies, etc. ### Steps to Analyze Memory Allocation 1. Open an existing application. 2. Choose Product, Profile as shown below. ![Image 5: mm_Profile](#) 3. Select Allocations and Profile in the following interface. ![Image 6: mm_ProfileSelect](#) 4. We can see the memory usage of different objects. 5. You can switch view controllers to check if memory is released. ![Image 7: mm_Instruments_Allocations](#) 6. Similarly, we can use the Activity Monitor to see how memory is allocated in the application. ![Image 8: mm_Instruments_ActivityMonitor](#) 7. These tools can help us understand memory usage and identify where leaks might occur.
← Ios Application DebuggingIos Gamekit β†’