【发布时间】:2015-03-31 14:18:37
【问题描述】:
当我使用GlobalLayoutListener 查看软键盘是否打开时,片段被销毁后不再是garbageCollected。
我做什么:
- 我在 Fragment 的
onDestroy()中删除了 Listener - 我在
onDestroy()中将监听器设置为null - 我在
onDestroy()中将观察到的视图设置为空
仍然泄漏片段。
有没有人遇到过类似的问题并知道解决方法?
我的onDestroy:
@Override
public void onDestroy(){
Log.d(TAG , "onDestroy");
if(Build.VERSION.SDK_INT < 16){
view.getViewTreeObserver().removeGlobalOnLayoutListener(gLayoutListener);
}else{
view.getViewTreeObserver().removeOnGlobalLayoutListener(gLayoutListener);
}
view = null;
gLayoutListener = null;
super.onDestroy();
}
【问题讨论】:
-
能否请您展示一下您的
onDestroy方法? -
@marcel,我为您发布了一个可能的解决方案。
标签: android android-fragments memory-leaks