We have a fairly extensive three.js application using quite a few materials, scenes, render buffers etc. We could only refresh/restart it a couple of times and it would fail on one of several issues; all of which amounted to running out of WebGL resources.
I have added a cleanup routine on window.onbeforeunload, that calls dispose() methods on the objects that support it; materials, renderBuffers and geometries. I'm not convinced I have caught all resources; but it seems to have been enough as I have been able to refresh every five seconds for half an hour.
The questions are: [1] What is the best way to trigger such a cleanup? window.onbeforeunload seems quite effective, but maybe there is reason to choose some alternative?
[2] What is the best way to perform such a cleanup? It would be good to have a dispose on the renderer that cleaned up all the WebGL resources. (I'm not concerned about the javascript objects, as the browser seems quite capable of cleaning those up.)
I have seen related questions here; eg on cleaning up scenes, but I am interested in a complete cleanup. I guess any answer at the lower WebGL level would work too for this global cleanup; which it might not for just some three.js resources as it wouldn't be able to work out the scope of these smaller cleanups.