forked from 0x2620/oxjs
some redesign for better garbage collection of elements
This commit is contained in:
parent
01f02d9730
commit
1d09d19423
17 changed files with 129 additions and 101 deletions
43
source/Ox.UI/js/Core/Ox.GarbageCollection.js
Normal file
43
source/Ox.UI/js/Core/Ox.GarbageCollection.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
|
||||
Ox.GarbageCollection = (function() {
|
||||
|
||||
var that = function() {
|
||||
collect();
|
||||
};
|
||||
|
||||
setInterval(collect, 60000);
|
||||
|
||||
function collect() {
|
||||
var len = Ox.len(Ox.UI.elements);
|
||||
Object.keys(Ox.UI.elements).forEach(function(id) {
|
||||
if (
|
||||
Ox.UI.elements[id]
|
||||
&& Ox.isUndefined(Ox.UI.elements[id].$element.data('oxid'))
|
||||
) {
|
||||
Ox.UI.elements[id].remove();
|
||||
delete Ox.UI.elements[id];
|
||||
}
|
||||
});
|
||||
Ox.Log('GC', len, '-->', Ox.len(Ox.UI.elements));
|
||||
}
|
||||
|
||||
that.debug = function() {
|
||||
var classNames = {}, sorted = [];
|
||||
Ox.forEach(Ox.UI.elements, function(element, id) {
|
||||
var className = element.$element[0].className;
|
||||
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;
|
||||
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue