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

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





On Tue, Jun 28, 2011 at 11:47 AM, Glenn Maynard <glenn@zewt.org> wrote:
On Sat, Jun 25, 2011 at 2:37 PM, Benoit Jacob <bjacob@mozilla.com> wrote:
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.

It's hard to imagine a WebGL app that would run all that long if it did anything like this. A 512meg card would fill up on a image viewer after 500 images or less.  A video player would run out of memory in probably 5-15 seconds.

On top of that, unless you are forcing a GC if OpenGL runs out of memory, cleaning up on GC won't help.
 

This is definitely a bug.  Objects should not hold implicit references to other objects.

A straightforward analogy is HTMLDocument (WebGLRenderingContext) to HTMLImageElement (WebGLTexture).  If you remove an image from a document and discard the reference, the document must not keep a reference to the image around; the image must eventually be collected.  You don't have a guarantee of when, but it's *not* tied to the lifetime of the document.

The existance of glDeleteTexture doesn't change this.  Developers *should* delete textures explicitly, in order to reclaim texture memory deterministically, but if they don't do so the resource should still always be GC'd eventually, not kept in memory by the context.

The issue here seems straightforward: the WebGLRenderingContext's table should be using weak references, to keep whatever extra information about the objects they need without preventing the resource from being collected.

Sure an implementation should probably do this but a WebGL app can't count on GC saving them from sloppy WebGL resource management.
 

--
Glenn Maynard