問(wèn)題描述
很多人注意到活動(dòng)中的 EditText 持有對(duì)活動(dòng)的強(qiáng)引用,即使它完成后也是如此.要清楚,此 EditText 位于布局內(nèi)并膨脹,沒(méi)有設(shè)置 Listeners.這只發(fā)生在某些設(shè)備上,例如三星 Galaxy S4 (Android 4.2.2) 等.許多關(guān)于此的帖子仍然沒(méi)有解決方案.首先是一些有用的帖子.(最終 GC 會(huì)清除它,因此從技術(shù)上講它不是泄漏,但對(duì)于內(nèi)存大的應(yīng)用程序來(lái)說(shuō),它需要很長(zhǎng)時(shí)間并且會(huì)導(dǎo)致 OOM)
Alot of people are noticing EditText in an activity is holding a Strong Reference to an Activity even once its finished. To be clear this EditText is inside a layout and inflated, there is no Listeners set. This only happens on certain devices e.g. Samsung Galaxy S4 (Android 4.2.2) and others. Many post about this still no solution. First here is some useful posts. (Eventually GC will clean this so its not technically a leak, but for heavy memory apps it takes way to long and will cause OOM)
Android Samsung Memory leak in EditText
Why does EditText retain its Activity's Context in Ice Cream Sandwich
EditText causing memory leak
Possibility of unhandled memory leak
The solutions noted do not work for all devices. It comes down to the Edittext Watcher. I think there may be solution in overriding this Watcher then having a function to clean it up onDestroy(). Please any help here, I been at this for days.
Here is the MAT Histogram
It is because EditText references the context of Activity. When the Activity is destroyed, Activity cannot be recycled normally because Edittext holds a reference to the context of activity. Solution: Rewrite EditText, change the reference to the Context in Activity to the reference to ApplicationContext.
Instructions:
https://programming.vip/docs/solve-the-memory-leak-problem-caused-by-edittext-in-android.html
這篇關(guān)于Android EditText 內(nèi)存泄漏的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!