How to stop Garbage collection in Android 2.3.3

拈花ヽ惹草 提交于 2020-01-02 20:10:43

问题


I have android application 2.3.3 use calendarView when press button => show dialog (contain calendarView)

My logcat display:

D/dalvikvm(15292): GC_CONCURRENT freed 1988K, 10% free 20024K/22087K, paused 4ms+3ms
D/dalvikvm(15292): GC_CONCURRENT freed 1995K, 10% free 20022K/22087K, paused 4ms+3ms
D/dalvikvm(15292): GC_CONCURRENT freed 1986K, 10% free 20029K/22087K, paused 4ms+3ms
D/dalvikvm(15292): GC_CONCURRENT freed 2005K, 10% free 20023K/22087K, paused 4ms+3ms
D/dalvikvm(15292): GC_CONCURRENT freed 1995K, 10% free 20016K/22087K, paused 4ms+3ms
D/dalvikvm(15292): GC_CONCURRENT freed 1997K, 10% free 20022K/22087K, paused 3ms+4ms

It slows down my app... I think Garbage collection paused my app Please help me show it quickly!

Thanks!


回答1:


Garbage Collector is a daemon thread. You can neither stop it nor call it. You can just make a request, eg.- System.gc(), to the garbage collector.

Plus, garbage collector helps improving the performance.

If you do not want to get your objects getting collected by GC then just Hold the reference.

If your object is getting collected prematurely, it is a symptom that you have a bug in the design of your application.




回答2:


When implementing applications (like games etc) that need to avoid garbage collection because of the small pauses it introduces every time the garbage collector executes,

All you can do is avoid to keep on creating objects and try to reuse as much as possible the objects instances you already have.

This can be done in different ways take a look at this




回答3:


When using CalendarView I noticed one quite surprising thing. When I set calendar heigh as number, ex. android:layout_height="400dp" garbage collector is not run, however when I set it as match_parent garbage collector is run every time I switch orientation. Perhaps that's the answer?




回答4:


i resolved my problem. because my dialog have RelativeLayout to contain calendarView. i changed RelativeLayout to LinearLayout => Garbage collection not start

Thanks!



来源:https://stackoverflow.com/questions/15356344/how-to-stop-garbage-collection-in-android-2-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!