安卓的EditText内存泄漏 [英] Android EditText Memory Leak

查看:2897
本文介绍了安卓的EditText内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人在活动注意到的EditText的金润持有的强引用一个活动,甚至一旦其完成。需要明确的是这的EditText是一个布局内充气,不存在侦听器设置。这只是发生在某些设备如三星Galaxy S4(安卓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)

中的EditText Android的三星内存泄漏

Android Samsung Memory leak in EditText

<一个href="http://stackoverflow.com/questions/8497965/why-does-edittext-retain-its-activitys-context-in-ice-cream-sandwich">Why确实的EditText保留其活性的语境冰淇淋三明治

的EditText导致内存泄漏

的未处理的内存泄漏可能性

该解决方案注意到没有适用于所有设备。它归结为EDITTEXT看守。我觉得有可能是覆盖此看守然后有一个函数来清理的onDestroy()解决方案。这里请任何帮助,我一直在这几天。

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.

下面是MAT柱状图

推荐答案

我困惑了很长一段时间这种内存泄漏。但最近我发现了两种方法来解决这个问题。

I was confused about this memory leak for a very long time. But recently I found two ways to fix this problem.

  1. 我发现,如果你的TextView / EditText上有安卓提示属性,这是不可能发生的。所以,最简单的方法就是给每一个的TextView / EditText上的提示属性。

  1. I found that if your TextView/EditText has the android:hint property, this cannot happen. So the easiest way is give every TextView/EditText the hint property.

最有力的方式就是反映过来的TextLine并找到听众返回ChangeWatcher,然后杀了这个监听器。

The most forceful way is to reflect over TextLine and find the ChangeWatcher listener, then kill this listener.

这篇关于安卓的EditText内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆