Saw that in some example codes, but ive never used it, unless im dynamically opening new diff开发者_Go百科erent sized textures etc.
So does my OS or something take care of freeing the texture memory when my app is terminated? Or do i have to free it myself ?
From Android GLSurfaceView.Renderer documentation:
public abstract void onSurfaceCreated (GL10 gl, EGLConfig config)
Since: API Level 3 Called when the surface is created or recreated. Called when the rendering thread starts and whenever the EGL context is lost. The EGL context will typically be lost when the Android device awakes after going to sleep. Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here. Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.
Like every other resource, most OSes will free them if you don't.
Usually, the reason to do it is to make sure you don't leak any resource while your program is running though. Say for example you load levels, if you don't free all you textures as you keep loading levels, sooner or later, you will run out of memory. Keeping track of leaks is easier if you clean up on exit.
精彩评论