每当我使用Android手机上的"主页"按钮离开我的应用程序并使用启动器图标再次进入应用程序时,我的应用程序的初始活动就会重复.如果我重复例程五次,我的初始活动有五个实例.
我通过Eclipse中的堆转储对此进行了监视,确保在每次转储之前进行垃圾回收.这是我在直方图视图中询问GC Root的Merge Shortes Path以及我的activity类的所有引用时获得的视图:
Class Name | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap
-------------------------------------------------------------------------------------------------------------------------------------------------
| | | |
android.view.ViewRootImpl$WindowInputEventReceiver @ 0x41408a80 Native Stack | 1 | 32 | 224 | 184
class android.view.inputmethod.InputMethodManager @ 0x40d93e78 System Class | 1 | 88 | 224 | 616
'- mInstance android.view.inputmethod.InputMethodManager @ 0x413422e0 | 1 | 112 | 224 | 296
'- mServedView, mNextServedView android.widget.ListView @ 0x41331100 | 1 | 1 088 | 224 | 124 096
'- mContext nilsnett.chinese.activities.GameOverviewActivity @ 0x44eeecd8| 1 | 224 | 224 | 1 000
android.view.ViewRootImpl$WindowInputEventReceiver @ 0x41af4a60 Native Stack | 1 | 32 | 224 | 184
android.view.ViewRootImpl$WindowInputEventReceiver @ 0x412cf928 Native Stack | 1 | 32 | 224 | 184
android.view.ViewRootImpl$WindowInputEventReceiver @ 0x44cd3090 Native Stack | 1 | 32 | 224 | 184
'- this$0 android.view.ViewRootImpl @ 0x44cd1f20 | 1 | 464 | 224 | 2 168
'- mView com.android.internal.policy.impl.PhoneWindow$DecorView @ 0x44cbef00| 1 | 536 | 224 | 1 336
'- mContext nilsnett.chinese.activities.GameOverviewActivity @ 0x44cbdee8| 1 | 224 | 224 | 1 000
Total: 5 entries | 5 | 216 | 1 120 |
-------------------------------------------------------------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
所以似乎有一个属性(或类?)WindowInputEventReceiver保持对我的活动的引用GameOverviewActivity.为什么,我该如何阻止它?
小智 -2
我发现原因是WindowInputEventReceiver实现了finalize方法\xef\xbc\x8cit导致引用。我打电话System.gc来onDestroy解决这个问题。
| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |