[Android][Memory Leak] InputMethodManager内存泄露现象及解决
现象:
在特定的机型天语k_touch_v9机型上,某个界面上出现InputMethodManager持有一Activity,导致该Activity无法回收.如果该Activity再次被打开,则旧的会释放掉,但新打开的会被继续持有无法释放回收.MAT显示Path to gc如下:
图1. Leak path
天语k_touch_v9手机版本信息:
图2. K_touch_v9
一番搜索后,已经有人也碰到过这个问题(见文章最后引用链接),给出的方法是:
@Override
public void onDestory() {
//Fix memory leak: http://code.google.com/p/android/issues/detail?id=34731
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.windowDismissed(this.getWindow().getDecorView().getWindowToken()); // hide method
imm.startGettingWindowFocus(null); // hide method
super.onDestory();
}
但在实践中使用后,没有真正解决,Activity仍存在,但path to gc指向为