May 21, 2021 iOS Development Manual
The basic idea of memory management under iOS is to reference count, which controls the life cycle of memory objects through the reference count of objects. There are two main ways to program time:
1: MRR (manual retain-release), manual reference count, object generation, destruction, reference count changes are done by the developer.
2: ARC (Automatic Reference Counting), which automatically references counts and is only responsible for the generation of objects, is no longer of concern to other process developers and is used in a manner similar to garbage collection, but is essentially a reference count.
According to Apple's documentation, the two main issues are:
The data released or overwritten is still in use. This can cause memory corruption, usually in application crashes, or worse, damage to user data.
Not releasing data that is no longer in use can result in memory leaks. A llocated memory, memory leaks are not released, even if it is never used again. Leaks can lead to increasing memory usage for applications, which in turn can result in poor system performance or crashes.
We create our own objects and release them when they no longer need them.
Keep the objects you need to use. If there is no need to release these objects.
Don't release objects we don't have.
Memory usage can be analyzed with the help of Xcode tool instruments. It includes tools such as Activity Monitor, Distribution, Leak, Zombie, etc
1. Open an existing application.
2. Select the product, as shown in the profile below
3. Select Allocations and Profile in the following interface.
4. We can see the memory usage of different objects
5. You can switch view controllers to see if memory is freed.
6. Similarly, we can use Activity Monitor to see how the allocation is in the application.
7. These tools can help us understand how memory is used and where leaks can occur.