Leaked memory: Memory unreferenced by your application that cannot be used again or freed (also detectable by using the Leaks instrument).
Abandoned memory: Memory still referenced by your application that has no useful purpose.
Cached memory: Memory still referenced by your application that might be used again for better performance.
此中 Leaked memory 和 Abandoned memory 都属于应该开释而没开释的内存,都是内存泄露,而 Leaks 工具只负责检测 Leaked memory,而不管 Abandoned memory。在 MRC 期间 Leaked memory 很常见,由于很容易忘了调用 release,但在 ARC 期间更常见的内存泄露是循环引用导致的 Abandoned memory,Leaks 工具查不出这类内存泄露,应用有限。
对于 Abandoned memory,可以用 Instrument 的 Allocations 检测出来。检测方法是用 Mark Generation 的方式,当你每次点击 Mark Generation 时,Allocations 会天生当前 App 的内存快照,而且 Allocations 会记载从上回内存快照到这次内存快照这个时间段内,新分配的内存信息。缺点是必要重复操纵,其无法实时得知泄漏