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