每次重新启动使用不同TextureAtlas的关卡时,我都会加载TextureAtlases:
public void LoadAllTextures(){
if(atlas_main!=null) atlas_main.dispose();
if(atlas_secondary!=null) atlas_secondary.dispose();
assets.clear();
assets.load(MAIN_ATLASABACK1_ATLAS, TextureAtlas.class);
assets.load(MAIN_ATLASABACK1_SKIN, Skin.class);
assets.finishLoading();
if(!assets.isLoaded(MAIN_ATLASABACK1_ATLAS)){ try { Thread.sleep(250); } catch (Exception e) { e.printStackTrace(); }
} else { atlas_main = assets.get(MAIN_ATLASABACK1_ATLAS); }
if(!assets.isLoaded(MAIN_ATLASABACK1_SKIN)){ try { Thread.sleep(250); } catch (Exception e) { e.printStackTrace(); }
} else { skin_main = assets.get(MAIN_ATLASABACK1_SKIN); }
assets.load(MAIN_ATLAS_SEC_ATLAS, TextureAtlas.class);
assets.finishLoading();
if(!assets.isLoaded(MAIN_ATLAS_SEC_ATLAS)){ try { Thread.sleep(250); } catch (Exception e) { e.printStackTrace(); }
} else { atlas_secondary = assets.get(MAIN_ATLAS_SEC_ATLAS); }
atlas_main.getTextures().first().bind();
atlas_secondary.getTextures().first().bind();
}
在5-10级重启后,在一些较弱(硬件方式)的手机上,FPS从恒定的60-61 FPS降至15-20 FPS或根本不动。每次我调用LoadAllTextures
时,我都会在Logcat中获得grow heap (frag case)
。这是一个屏幕截图:
如何避免这种堆分配并重新启动我想要的任何次数?