Hi,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this; var loader = new THREE.XHRLoader( scope.manager ); loader.setCrossOrigin( this.crossOrigin ); loader.load( url, function ( text ) { onLoad( scope.parse( text ) );
}, onProgress, onError ); }, |
From what I know, it looks like loader is a locally scoped to the load function. The inner callback is only a closure on the function onLoad and scope - no references to loader. This means at the end of the load function, loader should be out of scope and get cleaned up. However this does not happen, and the callback is called when the loader completes.
I duplicated the code in v8 and ran it with standard GC (IdleNotification) and aggressive GC (LowMemoryNotification). With the standard GC, the loader is not destroyed (right away) and the callback is called. Running in aggressive the loader is destroyed at the end of the function immediately <== this is the part that confuses me. Three.JS can't be doing this wrong can they? Am I missing something with regards to closures that I'm not aware of?
Any insights or pointing me in the right direction would be greatly appreciated. Thanks.
Vom