我正在尝试完全处理我的资产管理器中的所有纹理,并将内存使用量返回到它开始的位置。我做了一个非常简单的测试程序,尝试使用一个名为AssetManager的静态类,填充1000个纹理,然后处理所有这些。我的目标是达到它开始的内存使用量。当我运行程序时,我使用的是35兆字节。然后我单击回车填充列表,程序达到大约500兆字节。然后我单击空格清除,程序然后以65兆字节运行。我开始的几乎是双重的!这是名为Test
的测试AssetManager类 public class Test {
public static Hashtable<String, Texture> textureList = new Hashtable<String, Texture>();
public static void put(String key, Texture texx){
textureList.put(key, texx);
}
public static Texture getTexture(String key){
return textureList.get(key);
}
public static void stressTest(int lim){
for(int i = 0; i < lim; i++){
textureList.put("Texture: " + i, new Texture(Gdx.files.internal("badlogic.jpg")));
}
}
public static void destroy(String key){
textureList.remove(key);
}
public static void dispose(){
for(int i = 0; i < textureList.size(); i++)
textureList.get("Texture: " + i).dispose();
textureList.clear();
}
public static int poolSize(){
return textureList.size();
}
}
这里是主类
的渲染方法 if(Gdx.input.isKeyJustPressed(Keys.SPACE)){
Test.dispose();
}
if(Gdx.input.isKeyJustPressed(Keys.ENTER)){
Test.stressTest(1000);
}
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
if(Test.poolSize() > 1)
for(int i = 0; i < Test.poolSize(); i++){
batch.draw(Test.getTexture("Texture: " + i), i, i, 10, 10);
}
batch.end();
对此的任何帮助都是巨大的,因为我的主程序是一个挖掘游戏,你可以想象很多处理纹理。另外请不要建议重复使用一个纹理,因为我的主游戏中有超过1500个不同的纹理。
**问题:**如何完全处理纹理,以便达到35兆字节的原始内存使用量