Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting WebGL contexts

I have a page that is using many many webgl contexts, one per canvas. canvases can be reloaded, resized, etc. each time creating new contexts. It works for several reloads, but eventually when I try to create a new context it returns a null value. I assume that I'm running out of memory.

I would like to be able to delete the contexts that I'm no longer using so I can recover the memory and use it for my new contexts. Is there any way to do this? Or is there a better way to handle many canvases?

Thanks.

like image 300
user2089247 Avatar asked Feb 20 '13 00:02

user2089247


1 Answers

This is a long standing bug in Chrome and WebKit

http://code.google.com/p/chromium/issues/detail?id=124238

There is no way to "delete" a context in WebGL. Contexts are deleted by garbage collection whenever the system gets around to it. All resources will be freed at that point but it's best if you delete your own resources rather than waiting for the browser to delete them.

As I said this is a bug. It will eventually be fixed but I have no ETA.

I would suggest not deleting canvases. Keep them around and re-use them.

Another suggestion would be tell us why you need 200 canvases. Maybe the problem you are trying to solve would be better solved a different way.

like image 59
gman Avatar answered Oct 14 '22 08:10

gman