问题描述
查看层次结构如下TabActivity - > ActivityGroups - >活动
使用MAT我发现TabWidget由TabHost是由InputMethodManager引用引用,因此TabWidget泄漏。在随后推出的应用程序的内存溢出错误被抛出。
同样我所有的活动都是由InputMethodManager还引用。(关闭应用程序都是我activitygroups,活动,tabactivity,tabhost和tabwidget被泄露!!后)
在正确完成的应用程序(击中返回键),以下是显示在logcat中WARN / InputManagerService(99):对非重点客户com.android.internal.view.IInputMethodClient$Stub$Proxy@44a87748开始输入(UID = 10052 PID = 1463)
如何从InputMethodManager删除提及...?
的事情,我尝试:答:叫我TabActivity这种方法的onDestroy 1.myTabWidget.removeAllViews() 2.myTabWidger.invalidate()没有运气!
已经发布问题Main活动不是垃圾回收后销毁,因为它是由InputMethodManager引用是间接的。
当然,它不会工作。活动不是观点无论是在MVC / MVP / MVVM也不在Android SDK中的类层次结构。 android.app.Activity没有延伸android.view.View
我的同事也有类似的问题,内存泄漏 - 他宣称tabHost在TabActivity以静态的方式(他想从另一个活动的访问,当他没有熟悉的模式观察员)。我认为你做了类似的事情。
和,最后,我的问题:为什么你在InputMethodManager引用活动(虽然我不知道如何:这是最后一类),而不是InputMethodManager活动?如果你想为InputMethodManager全球焦点,我可以建议你把它引用应用程序类。我们扩展应用类(例如,HostApplication),在该门面我们宣布共同的东西(共享preferences,例如)。而在活动中,我们写的:
HostApplication应用=(HostApplication)getApplication();
然后我们得到有用的共同的东西从它。
View hierarchy is as follows TabActivity -> ActivityGroups -> Activities.
Using MAT I found that TabWidget is referenced by TabHost which is referenced by InputMethodManager, hence TabWidget is leaked. On Subsequent launch of application OutOfMemory Error is thrown.
Similarly all my activities are also referenced by InputMethodManager.(After closing the application all my activitygroups, activities, tabactivity, tabhost and tabwidget are leaked!!)
On Properly finishing the application(hitting back key), following is shown in logcatWARN/InputManagerService(99): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44a87748 (uid=10052 pid=1463)
How to remove the reference from InputMethodManager...?
Thing I tried:A. Called this method onDestroy of my TabActivity 1.myTabWidget.removeAllViews() 2.myTabWidger.invalidate()No Luck!
Already Posted questionMain Activity is not garbage collected after destruction because it is referenced by InputMethodManager indirectly.
Of course, it will not work. Activities aren't views neither in MVC/MVP/MVVM nor in Android SDK classes hierarchy. android.app.Activity doesn't extend android.view.View
My colleague had similar problem with memory leaks - he declared tabHost in TabActivity in static way (he wanted to access it from another activity, when he hadn't been familiar with pattern Observer). I think you've made something similar.
And, at last, my question: why do you reference activities in InputMethodManager (though I don't understand how: it's final class) and not InputMethodManager in activities? If you want global focus point for InputMethodManager, I can advice you to put reference of it to Application class. We extend Application class (for example, HostApplication), in this facade we declare common stuff (SharedPreferences, for example). And in the activities we write:
HostApplication application = (HostApplication) getApplication();
Then we get useful common stuff from it.
这篇关于InputMethodManager持有参考tabhost - 内存泄漏 - OOM错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!