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)該釋放而沒釋放的內(nèi)存碎捺,都是內(nèi)存泄露路鹰,而 Leaks 工具只負(fù)責(zé)檢測 Leaked memory,而不管 Abandoned memory收厨。在 MRC 時(shí)代 Leaked memory 很常見晋柱,因?yàn)楹苋菀淄苏{(diào)用 release,但在 ARC 時(shí)代更常見的內(nèi)存泄露是循環(huán)引用導(dǎo)致的 Abandoned memory诵叁,Leaks 工具查不出這類內(nèi)存泄露雁竞,應(yīng)用有限。
1.通過Xcode-profile打開instrument
2.選擇真機(jī)運(yùn)行
3.選擇 Allocations -- Generations 檢測每次每次內(nèi)存增長多少
4. 使用leaks查看的內(nèi)存泄漏的具體代碼