[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Lifetime of WebGL objects in Firefox and Webkit
On Sat, Jun 25, 2011 at 2:37 PM, Benoit Jacob <email@example.com>
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.
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.