2012-02-04 08:58:46 +00:00
|
|
|
'use strict';
|
2011-11-04 22:14:30 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-22 13:14:40 +00:00
|
|
|
Ox.GarbageCollection <f> GarbageCollection
|
2012-05-21 10:38:18 +00:00
|
|
|
() -> <o> run garbage collection
|
|
|
|
debug() -> {} output debug information
|
|
|
|
@*/
|
|
|
|
|
2011-11-04 22:14:30 +00:00
|
|
|
Ox.GarbageCollection = (function() {
|
|
|
|
|
|
|
|
var that = function() {
|
2012-01-21 11:30:16 +00:00
|
|
|
collect();
|
|
|
|
},
|
|
|
|
timeout;
|
2011-11-04 22:14:30 +00:00
|
|
|
|
2012-01-21 11:30:16 +00:00
|
|
|
collect();
|
2011-11-04 22:14:30 +00:00
|
|
|
|
|
|
|
function collect() {
|
2014-09-24 08:26:51 +00:00
|
|
|
var len = Ox.len(Ox.elements);
|
|
|
|
Object.keys(Ox.elements).forEach(function(id) {
|
|
|
|
var $element = Ox.elements[id];
|
2014-09-22 14:25:43 +00:00
|
|
|
if ($element && Ox.isUndefined($element.data('oxid'))) {
|
2012-06-23 18:23:19 +00:00
|
|
|
$element.remove();
|
2014-09-24 08:26:51 +00:00
|
|
|
delete Ox.elements[id];
|
2011-11-04 22:14:30 +00:00
|
|
|
}
|
|
|
|
});
|
2012-01-21 11:30:16 +00:00
|
|
|
timeout && clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(collect, 60000);
|
2014-09-24 08:26:51 +00:00
|
|
|
Ox.Log('GC', len, '-->', Ox.len(Ox.elements));
|
2011-11-04 22:14:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
debug <f> debug info
|
|
|
|
() -> <s>
|
|
|
|
@*/
|
2011-11-04 22:14:30 +00:00
|
|
|
that.debug = function() {
|
|
|
|
var classNames = {}, sorted = [];
|
2014-09-24 08:26:51 +00:00
|
|
|
Ox.forEach(Ox.elements, function($element, id) {
|
2012-06-26 16:01:47 +00:00
|
|
|
var className = $element[0].className;
|
2011-11-04 22:14:30 +00:00
|
|
|
classNames[className] = (classNames[className] || 0) + 1;
|
|
|
|
});
|
|
|
|
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) {
|
|
|
|
return v.count + ' ' + v.className
|
|
|
|
}).join('\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2012-02-04 08:58:46 +00:00
|
|
|
}());
|