Leaks
先看看 Leaks,從蘋果的開發(fā)者文檔里可以看到,一個(gè) app 的內(nèi)存分三類:
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 都屬于應(yīng)該釋放而沒(méi)釋放的內(nèi)存,都是內(nèi)存泄露,而 Leaks 工具只負(fù)責(zé)檢測(cè) Leaked memory,而不管 Abandoned memory。在 MRC 時(shí)代 Leaked memory 很常見(jiàn),因?yàn)楹苋菀淄苏{(diào)用 release,但在 ARC 時(shí)代更常見(jiàn)的內(nèi)存泄露是循環(huán)引用導(dǎo)致的 Abandoned memory,Leaks 工具查不出這類內(nèi)存泄露,應(yīng)用有限。
1.通過(guò)Xcode-profile打開instrument

2.選擇真機(jī)運(yùn)行

3.選擇 Allocations -- Generations 檢測(cè)每次每次內(nèi)存增長(zhǎng)多少

4. 使用leaks查看的內(nèi)存泄漏的具體代碼