iOS專項(xiàng)測(cè)試--instrument的Leaks / Allocations檢測(cè)內(nèi)存的使用

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

1

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

3

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

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容