Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a SpriteBatch instance need to call dispose() once it is no longer used?

Tags:

libgdx

According to this article, a SpriteBatch instance needs to call dispose() once it is no longer needed. However, as I examine some of libgdx's official examples like Pax Britannica and Super Jumper, I found out that they never call SpriteBatch.dispose(). Why is that?

like image 882
Hải Phong Avatar asked Nov 08 '13 06:11

Hải Phong


1 Answers

SpriteBatch must always be disposed.

Internally, it creates and manages several Mesh objects. These objects allocate vertex/index arrays on the GPU. Those are only deallocated if you explicitly call Mesh#dispose(), which will be triggered by calling dispose() on your SpriteBatch object.

It will also, by default, create its own ShaderProgram. And similarly, would be leaked if you didn't call dispose().

If the demo's aren't doing this, perhaps it's time to send a pull request!

like image 61
Richard Taylor Avatar answered Sep 17 '22 23:09

Richard Taylor