update Ox.GarbageCollection: use .collect to collect; don't run immediately

This commit is contained in:
rlx 2014-09-25 18:32:01 +02:00
parent 86f1bad4eb
commit 86bee39b51

View file

@ -8,14 +8,10 @@ Ox.GarbageCollection <f> GarbageCollection
Ox.GarbageCollection = (function() {
var that = function() {
collect();
},
var that = {},
timeout;
collect();
function collect() {
that.collect = function() {
var len = Ox.len(Ox.elements);
Object.keys(Ox.elements).forEach(function(id) {
var $element = Ox.elements[id];
@ -25,9 +21,9 @@ Ox.GarbageCollection = (function() {
}
});
timeout && clearTimeout(timeout);
timeout = setTimeout(collect, 60000);
timeout = setTimeout(that.collect, 60000);
Ox.Log('GC', len, '-->', Ox.len(Ox.elements));
}
};
/*@
debug <f> debug info
@ -41,7 +37,7 @@ Ox.GarbageCollection = (function() {
});
Ox.forEach(classNames, function(count, className) {
sorted.push({className: className, count: count});
})
});
return sorted.sort(function(a, b) {
return a.count - b.count;
}).map(function(v) {
@ -49,6 +45,8 @@ Ox.GarbageCollection = (function() {
}).join('\n');
};
setTimeout(that.collect, 60000);
return that;
}());