[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] Lifetime of WebGL objects in Firefox and Webkit


As far as I can see, in both Firefox and Webkit, the WebGLRenderingContext stores a hash table of reference pointers to all the WebGL objects associated to this context, such as textures.

This means that unreferenced objects such as textures are kept alive until the WebGLRenderingContext gets destroyed. The only way to destroy a WebGL texture earlier than the context itself, is to call deleteTexture explicitly.

It's easy to imagine (admittedly bad) JS code that would inadvertently cause a leak because of that.  Imagine a video player that would create a new texture object for each frame, let it go out of scope and naively expect that to destroy it.

Should we implement a change making the WebGLRenderingContext no longer keep WebGL objects alive?

While I'm at it, here are some spec nits. The spec says this about WebGLTexture:

"The WebGLTexture interface represents an OpenGL Texture Object. The underlying object is created as if by calling glGenTextures (OpenGL ES 2.0 §3.7.13, man page) , bound as if by calling glBindTexture (OpenGL ES 2.0 §3.7.13, man page) and destroyed as if by calling glDeleteTextures (OpenGL ES 2.0 §3.7.13, man page) . "

I can parse this as perfectly good English but don't understand what it _specifies_.

The spec also says:

> void deleteTexture(WebGLTexture texture) (OpenGL ES 2.0 §3.7.13, man page)
>    Delete the texture object contained in the passed WebGLTexture as if by calling glDeleteTextures. If the texture has already been deleted the call has no effect. Note that the texture object will be deleted when the WebGLTexture object is destroyed. This method merely gives the author greater control over when the texture object is destroyed. 

As a naive implementer reading this, my questions is "should deleteTexture actually call glDeleteTextures immediately?", the beginning of the above paragraph suggests so ("as if by calling glDeleteTextures") but the rest casts doubt on that: "Note that the texture object will be deleted when the WebGLTexture object is destroyed." This suggests that the texture object only gets destroyed when the actual WebGLTexture JS object is destroyed i.e. on the next GC after all references to it were lost. In any case, both Firefox and Webkit destroy the texture immediately in deleteTexture.


You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl