简体   繁体   English

在Libgdx中创建另一个纹理时应该调用dispose()纹理吗?

[英]Should i call dispose() texture when create another texture in Libgdx?

I'm creating a game with Libgdx. 我正在用Libgdx创建游戏。 My game will load a image and show on screen like this: 我的游戏将加载图像并显示在屏幕上,如下所示:

sprite = new Sprite(texture1);

And then it will load another image in few seconds and show it. 然后它将在几秒钟内加载另一个图像并显示它。

sprite = new Sprite(texture2);

So, should I call spirte.getTexture().dispose() before I load the second image? 因此,在加载第二个图像之前,我应该调用spirte.getTexture().dispose()吗? Or when we create new Sprite, the fist Texture will be dispose automatically? 还是当我们创建新的Sprite时,拳头Texture会被自动处理?

Yes, it must be called on any disposable object before you lose your reference to it or there will be a memory leak. 是的,必须在任何一次性对象上调用它,然后再丢失对它的引用,否则会发生内存泄漏。

If you are going to use a Texture for the lifetime of your game, you might not be planning to ever need to dispose it, but on Android you still have to in the Game's dispose method because there are cases where Android will shut down your Activity but not the entire Application so when the user reopens your game, all the previous textures are leaked. 如果您打算在游戏的整个生命周期内使用Texture,则可能不需要计划进行处理,但是在Android上,您仍然必须使用Game的dispose方法,因为在某些情况下,Android会关闭您的Activity而不是整个应用程序,因此当用户重新打开游戏时,所有以前的纹理都会泄漏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM