@@ -75,19 +75,19 @@ exports.add = function (key, callback) {
7575 return false ;
7676 }
7777
78- bucket = callbackQueue [ key ] = [ callback ] ;
79-
80- /**
81- * This is wrapped in once so that we might escape all sorts of shit-like code
82- * where people forget to remove certain even listeners and callback can be called
83- * twice, but for another request. If you are certain that your code lacks these
84- * stupid mistakes - you are more than welcome to fork and remove this restriction
85- */
78+ callbackQueue [ key ] = [ callback ] ;
79+
8680 return function queuedCallback ( ) {
81+ // its essential that we do not use any reference, because of garbabe collection
82+ // when object reaches certain number of nullified values - its recreated using compactObject
83+ // function. Therefore we need to grab a reference when callback needs to be invoked and not at
84+ // other time
85+ var callbacks = callbackQueue [ key ] ;
86+
8787 debug ( 'calling callback for key %s' , key ) ;
8888
89- if ( ! bucket || callbackQueue [ key ] !== bucket || ! isArray ( bucket ) ) {
90- debug ( 'Callbacks couldn\'t be invoked: ' , bucket , callbackQueue [ key ] !== bucket ) ;
89+ if ( ! isArray ( callbacks ) ) {
90+ debug ( 'Callbacks couldn\'t be invoked: ' , callbacks ) ;
9191 bucket = null ;
9292 return ;
9393 } else {
@@ -100,9 +100,8 @@ exports.add = function (key, callback) {
100100 args [ i ] = arguments [ i ] ;
101101 }
102102
103- iterateOverCallbacks ( bucket , args ) ;
103+ iterateOverCallbacks ( callbacks , args ) ;
104104 cleanup ( key ) ;
105- bucket = null ;
106105 } ;
107106
108107} ;
0 commit comments