我正在制作一个简单的游戏,当它第一次运行时完美运行没有问题,如果你完成一个关卡,打开高分屏幕(下面的run()方法),然后下次你玩然后它以第一轮速度的大约五分之一的速度运行。我有另一个线程,它是一个在两种情况下都能完美运行的计时器。我查看了代码并且找不到第二次运行速度慢的原因?有任何想法吗?
以下是从菜单屏幕打开关卡的代码。
public void fieldChanged(Field inField, int inContext){
final int level;
if(inField == button1)
level = 1;
else
if(inField == button2)
level = 2;
else
if(inField == button3)
level = 3;
else
if(inField == button4)
level = 4;
else
level = 0; //Ensures variable is initialised
game = new Game(level);
UiApplication.getUiApplication().pushScreen(game);
_invokeID = getApplication().invokeLater(new Runnable(){
public void run(){
if (game.getActive() == false){
getApplication().cancelInvokeLater(_invokeID);
getUiEngine().popScreen(game);
Dialog.inform("Final Score: " + String.valueOf(game.getScore()));
hs = new HighScore(game.getScore(), game.getTime(), level);
UiApplication.getUiApplication().pushScreen(hs);
game = null;
}
}
}, 500,true);
}
答案 0 :(得分:0)
使用jconsole / visualvm等检查程序java进程JVM的堆/ CPU使用情况统计信息。
如果JVM正在进行频繁的垃圾收集,那么它表明你的进程耗尽了堆内存,需要解决这个问题。
让我知道你的发现。