Java的控制垃圾收集器 [英] Java controlling garbage collector

查看:147
本文介绍了Java的控制垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的Andr​​oid游戏与OpenGLES 2.0,而我的游戏目前可以呈现高达每秒55-60帧,但我有一个垃圾收集器有点问题,它会减慢为每秒35帧,并且可以看到一个滞后而损害用户体验。它运行在完全随机的时刻。
搜索结果
我的问题:搜索结果
是否有可能以某种方式控制垃圾收集器的执行,比如我可以推迟GC 0.5秒或之前调用GC,并确保GC不会在接下来的两秒钟内叫什么名字?或者是有什么办法可以减少对应用程序执行GC的影响​​?

I'm creating Android game with OpenGLES 2.0, and my game currently can render up to 55-60 frames per second, but I have a little problem with Garbage Collector, it slows down to 35 frames per second, and you can see a lag which damage user experience. It runs in totally random moments.

My question:

Is it possible to somehow control execution of Garbage Collector, for example can I delay GC for 0.5s or call GC before and be sure that GC wouldn't be called in next two second? Or is there any way to reduce impact of GC on application execution?

推荐答案

当需要从使用的对象释放内存垃圾收集器开始。

The garbage collector starts when it needs to free the memory from unused objects.

操作的最好办法是减少重复使用旧的新对象的数量。

The best way to operate is reduce the number of new Objects reusing the old ones.

阅读您的code和每次你看到的时间新关键字问问自己的我真的需要一个新的对象吗?或者,我可以重置一个古老的未使用的对象?

Read your code and every time you see the new keyword ask yourself I really need a new Object here? Or I can reset an old unused Object?

尝试读取Android的开发者网站 HTTP提示://开发商。 android.com/training/articles/perf-tips.html

Try to read the tips in the developer android site http://developer.android.com/training/articles/perf-tips.html

注意: A调用System.gc()仅仅是垃圾收集系统时操作自动选择一个建议。从javadoc中的调用此方法的提示朝回收未物体Java虚拟机的努力......

Note: a call to System.gc() is just a suggestion for the garbage collection system that automatically choose when to operate. From javadoc "Calling this method suggests that the Java virtual machine expend effort toward recycling unused objects..."

这篇关于Java的控制垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆