Hi,
I'm a little confused on a scoping issue and was hoping someone could
enlighten me or point me in the right direction. I'm looking at the
three.js library and I see the following on line 19-27
(https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader.js).
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
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.