程序范例:静态变量,libgdx和android暂停/恢复内存使用
public class main extends ApplicationAdapter
{
public static int a;
public static int b;
public static Player player;
public void create()
{
resume();
}
public void render()
{
}
public void resize()
{
}
//pause runs when home button is pressed
public void pause()
{
player = null;
}
//resume runs when the program is re-opened
public void resume()
{
a = 10;
b = 20;
player = new Player();
}
}
在Android上,按下home键时,该程序保存在内存和静态变量保持它们的值。现在,当这个程序重新打开时,这个例子是否创建了新的静态变量或者只是将值分配给内存中的旧静态变量?
我这么问是因为我有了一个问题,即按家庭和重新打开程序导致内存每次增加,我想知道,如果这能起到为什么发生作用的程序。
更新:请问选手对象获取从内存中删除当它再被创建之前宣布无效?
运行调试,并看看会发生什么。最好的方法来找出IMO –