Android EditText Memory Leak(Android EditText 内存泄漏)
问题描述
很多人注意到活动中的 EditText 持有对活动的强引用,即使它完成后也是如此.要清楚,此 EditText 位于布局内并膨胀,没有设置 Listeners.这只发生在某些设备上,例如三星 Galaxy S4 (Android 4.2.2) 等.许多关于此的帖子仍然没有解决方案.首先是一些有用的帖子.(最终 GC 会清除它,因此从技术上讲它不是泄漏,但对于内存大的应用程序来说,它需要很长时间并且会导致 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
这篇关于Android EditText 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android EditText 内存泄漏
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01