我使用libGDX并在我不再需要它们时释放我的资源以释放RAM。游戏结束时我是否需要手动处理资源?或者这是由Android(或libGDX)自动完成的吗?
答案 0 :(得分:1)
是的,您必须,或者与所有这些对象关联的本机内存都将泄漏。在Android中关闭活动(这是托管Libgdx游戏的活动)不会关闭整个应用程序,因此操作系统不会回收内存,您将丢失对可以处置的对象的所有引用。
答案 1 :(得分:0)
事实是,某些物体需要手动处理 - 例如:参考它们是
和其他许多人you will find here。
为了便于管理您的资产,您应该使用AssetManager。如何使用is desribed here的方式,但一般模式是:
示例代码:
AssetManager assetManager = new AssetManager();
assetManager.load("data/mytexture.png", Texture.class);
assetManager.finishLoading(); //loading resources to asset manager is asynchrous! you can also use .update() method - find it in the reference
...
Texture tex = assetManager.get("data/mytexture.png", Texture.class); //use the asset manager to obtain texture
...
assetManager.clear(); //disposing asset manager with all its resources - you can also use .dispose() method