How to stop Garbage collection in Android 2.3.3

ⅰ亾dé卋堺 提交于 2019-12-06 04:27:50

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.

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

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?

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

Thanks!

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