Mob*_*Dev 6 android memory-leaks android-edittext android-textattributes
很多人注意到活动中的EditText即使一旦完成就会持有对活动的强引用.要清楚这个EditText在布局中并且已经膨胀,没有设置监听器.这仅发生在某些设备上,例如Samsung Galaxy S4(Android 4.2.2)和其他设备.很多帖子都说没有解决方案.首先是一些有用的帖子.(最终GC会清除它,所以它在技术上不是泄漏,但对于重型内存应用程序,它需要很长时间并将导致OOM)
为什么EditText在Ice Cream Sandwich中保留其Activity的Context
所提到的解决方案并不适用于所有设备.它归结为Edittext Watcher.我认为可能有一个解决方案来覆盖这个Watcher然后有一个函数来清理onDestroy().请帮忙,我已经好几天了.
这是MAT直方图

小智 -1
尝试在该特定视图的 onCreateView() 中使用应用程序上下文而不是活动上下文(其中包含任何 android:textIsSelectable="true" 组件)。
// Singleton
class MyApplication extends Application {
private static MyApplication mApp;
@Override
public void onCreate() {
mApp = this;
}
public static MyApplication getApp() {
return mApp;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Suggested inflater use Activity Context
// So we must tu use Application Context
Context context = MyApplication.getApp().getApplicationContext();
LayoutInflater myLayoutInflater = LayoutInflater.from(context);
View view = myLayoutInflater.inflate(R.layout.my_view, container, false);
return view;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3687 次 |
| 最近记录: |