fixed memory leak related to event removal

This commit is contained in:
Brandon Miller 2014-03-01 03:38:27 -08:00
parent ebe179e566
commit 4cacd8a919
2 changed files with 16 additions and 7 deletions

View file

@ -34,13 +34,18 @@ window.pubsub=(
return;
}
if(this._events_[type].length<2){
delete this._events_[type];
return;
}
for(var i=0,
count=this._events_[type].length;
count=this._events_[type].length;
i<count;
i++){
if(this._events_[type][i]==handler)
delete this._events_[type][i];
i++
){
if(this._events_[type][i]==handler)
this._events_[type].splice(i,1);
return;
}
}

View file

@ -11,7 +11,6 @@ function unsub(type,handler){
checkScope.apply(this);
if(type=='*'){
delete this._events_['*'];
for(
var keys = Object.keys(this._events_),
count = keys.length,
@ -31,13 +30,18 @@ function unsub(type,handler){
return;
}
if(this._events_[type].length<2){
delete this._events_[type];
return;
}
for(var i=0,
count=this._events_[type].length;
i<count;
i++
){
if(this._events_[type][i]==handler)
delete this._events_[type][i];
this._events_[type].splice(i,1);
return;
}
}