Now that we have adopted WeakMaps seems like a good time to try again adding lists of objects in memory.
We tried some years ago but WeakMap was not available in browsers and by using simple Arrays we were going to create memory leaks for use cases where the user relies in the JS garbage collector.
/cc @fernandojsg
@mrdoob I think i missed this topic in the past, can you detail a bit, what is it that you propose?
Correction: I meant WeakSet and not WeakMap.
Basically creating WeakSets so we can keep track of objects in memory.
new THREE.Texture() would have a THREE.Textures.add( this ) in its constructor.
This would allow users to keep track of objects they have created.
@mrdoob
sounds interesting, what would be the usecases for that, what could I do with this set?
Ah, so that they're plural forms. I first didn't notice that they're plural in the title.
Since WeakSet is a new data structure in ES6 gramma, what if people using old browser that doesn't support WeakSet? Maybe we should write a polyfill for it and check whether users' browsers support or not. If not support, a polyfill version WeakSet could be used.
There are existing polyfills for WeakSet– three.js does not bundle these in, but the docs list which to include, depending on what browsers you need to support: https://threejs.org/docs/#manual/introduction/Browser-support. Probably we should update that section to reflect IE11.
Cool! I'll try to submit a PR later today ;)
I'm not sure you will get anything useful using WeakSets - you can't iterate or count them, just test for existence or not of an object in the set.
Closing this for now. Thanks for the feedback guys!