在尝试修改Ext库,完善内存释放时发现
不管怎么改,form节点都一直释放不掉
自己写例子时,就算创建了dom节点后只赋给一个变量,sIEve显示的引用也有3个
抓狂了很久以后,上网查了下资料,发现是IE在作怪:
http://blog.archive.jpsykes.com/92/ie6-form-tag-orphans/index.html
作者也试过很多办法来清除,无一例外全失败了。
[quote]Approaches Tested
* innerHTML on parent (most common garbage collection)
* Using removeNode, rather than removeChild
* Using replaceNode before removing it
* Resetting all variables before removing it
* Giving it a HasLayout (I was desperate)
* Setting AutoComplete to off on the form
* collectGarbage()
* Crockfords Purge
* …
[/quote]
后面给的一个例子,其实是重用form节点:
无奈中。。。又不敢直接修改Ext框架的逻辑
看在这个节点占用内存也不多的面子上,不管它了。
不管怎么改,form节点都一直释放不掉
自己写例子时,就算创建了dom节点后只赋给一个变量,sIEve显示的引用也有3个
抓狂了很久以后,上网查了下资料,发现是IE在作怪:
http://blog.archive.jpsykes.com/92/ie6-form-tag-orphans/index.html
作者也试过很多办法来清除,无一例外全失败了。
[quote]Approaches Tested
* innerHTML on parent (most common garbage collection)
* Using removeNode, rather than removeChild
* Using replaceNode before removing it
* Resetting all variables before removing it
* Giving it a HasLayout (I was desperate)
* Setting AutoComplete to off on the form
* collectGarbage()
* Crockfords Purge
* …
[/quote]
后面给的一个例子,其实是重用form节点:
function MyForm() {
this.InstanceId = ''+MyForm.InstanceCounter++;
MyForm.Instances[this.InstanceId] = this;
for( var key in MyForm.Recycle ) {
this.Node = MyForm.Recycle[key];
delete MyForm.Recycle[key];
}
if( this.Node==null ) {
this.Node = document.createElement('FORM');
}
this.Node.InstanceId = this.InstanceId;
}
MyForm.prototype.InstanceId = null;
MyForm.prototype.Node = null;
MyForm.prototype.destroy = function() {
if( this.Node.parentNode ) this.Node.parentNode.removeChild(this.Node);
MyForm.Recycle[this.InstanceId] = this.Node;
delete MyForm.Instances[this.InstanceId];
this.Node = null;
}
MyForm.InstanceCounter = 1;
MyForm.Instances = {};
MyForm.Recycle = {};
// create and destroy 10000 forms
var a;
for( var i = 0; i <= 5000; i++){
//create a new form
var b = new MyForm();
// add the new form to the body
var a = document.body.appendChild(b.Node);
//destroy the form
b.destroy();
//break;
}
无奈中。。。又不敢直接修改Ext框架的逻辑
看在这个节点占用内存也不多的面子上,不管它了。