cedricpinson/osgjs — pull request #173 by jtorresfabra (2014-11-20 09:45:10+00:00)
Title: Viewer dispose -- Only for discussion/Not for Merge

I've added an example (examples/dispose) which destroys/creates a viewer with a simple scene. The goal is to find and solve memory leaks when viewer is disposed. To find leaks just create and destroy some viewers in the examples and then go to chrome developer tools and take a heap snapshot in the profiling section when you have no viewer in the screen. Just searching for elements like 'Uniform', 'Shader', 'Material', 'Light' or 'Viewport', in the snapshot will reveal some leaks. i.e: See attached image revealing a leak (multiple viewport instances still referenced probably in some osgShader/ShaderGenerator attribute).

I have found/fixed several leaks, even the Viewer/States objects are disposed (You shouldn't find any Viewer/State in the Snapshots). But osgjs still needs fixes for the elements said above and maybe some more.

Probably the use of Maps/Sets described in #172 could improve the situation. For example in the Uniform object in Light or Material.

Maybe I'm not doing the 'right' things to destroy all the osgjs related elements so any advice/comments/help would be great.

![image](https://cloud.githubusercontent.com/assets/1784900/5122486/9b696282-70a1-11e4-933b-2900a60f3097.png)

Thanks.