v_johan
v_johan

Reputation: 470

No need to do opengl delete functions in android?

I saw this: Android SurfaceView doc. Under the Context lost it says:

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted.

Does that mean that I don't have to call the for example GLES20.GLES20.glDeleteTextures( ... ); and that android will clean that up for me? I also see that no tutorial on android opengl es mentions the delete functions, not even the "official" ones on Developer.android.

(Ofcourse I assume that this is only applicable when I don't need more memory for my objects)

So do any of you know this? Do I have to delete opengl stuff manually?

Upvotes: 1

Views: 807

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54642

When a context is destroyed, all objects created within the context are automatically deleted. This behavior is defined in the ES 2.0 spec in appendix C under "Object Deletion Behavior":

Once the last context on the share list is destroyed, all shared objects, and all other resources allocated for that context or share list, will be deleted and reclaimed by the implementation as soon as possible.

Things get a little more complicated if you have multiple contexts. But in the single context case, all objects go away together with the context.

Of course if there are objects that you don't need anymore during execution, you should still delete them with the corresponding glDelete*() call. Otherwise you will have more and more objects piling up. But there is no need to delete objects during cleanup.

Upvotes: 4

Related Questions