Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix potential memory leak with removeEvent

  • Loading branch information...
commit ce95b08de2d1197436a31a61511c23b4e98927ce 1 parent 53c6283
@fat authored
Showing with 24 additions and 3 deletions.
  1. +24 −3 src/bean.js
View
27 src/bean.js
@@ -94,10 +94,12 @@
},
removeListener = function (element, orgType, handler) {
- var uid, names, uids, i, events = retrieveEvents(element), type = orgType.replace(stripName, '');
+ var uid = element.__uid, names, uids, i, events = retrieveEvents(element), type = orgType.replace(stripName, '');
+
if (!events || !events[type]) {
return element;
}
+
names = orgType.replace(namespace, '');
uids = names ? names.split('.') : [handler.__uid];
@@ -117,6 +119,15 @@
destroyHandler(names); //get combos
for (i = uids.length; i--; destroyHandler(uids[i])) {} //get singles
+ if (isEmpty(events[type])) {
+ delete events[type];
+ }
+
+ if (isEmpty(registry[uid])) {
+ delete registry[uid];
+ delete collected[uid];
+ }
+
return element;
},
@@ -167,7 +178,9 @@
if (attached.hasOwnProperty(k)) {
for (i in attached[k]) {
for (m = names.length; m--;) {
- attached[k].hasOwnProperty(i) && new RegExp('^' + names[m] + '::\\d*(\\..*)?$').test(i) && rm(element, [k, i].join('.'));
+ attached[k].hasOwnProperty(i)
+ && new RegExp('^' + names[m] + '::\\d*(\\..*)?$').test(i)
+ && rm(element, [k, i].join('.'));
}
}
}
@@ -264,7 +277,14 @@
}
}
return result;
- };
+ },
+
+ isEmpty = function (obj) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) return false;
+ }
+ return true;
+ }
fixEvent.preventDefault = function (e) {
return function () {
@@ -337,4 +357,5 @@
};
return bean;
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.