IE6 Form Tag Orphans
Had an interesting bug passed by me for “input” today, that I’ve consequently spent all evening playing around with and testing. It’s a doozy.
Apparently if you try to remove/destroy/trash a FORM dom node in IE6, it won’t delete it, instead creating a bizarre orphaned node stuck sucking up memory until the browser window is refreshed.
Why’s that an issue
If you have a “web application” that uses any form of partial page loading, and the content you are loading contains any form elements, in IE6 memory usage will climb as you use the app, leading to initially a sluggish browser and finally total terminal failure.
As many of the toolkits these days come with this style of content loading mechanism (take for example my toolkit of choice dojo, with it’s contentPanes), it’s very easy to get into a situation where your webapp will be unacceptable to folks using IE.
I sat down and put together a series of test cases (beware these will do nothing interesting in anything other than sIEve, so you really need to run them in there (but I do attach screen shots in case you don’t have sIEve close to hand).
The craziest thing is that after doing some fairly comprehensive research, I found only 1 other mention of this specific issue, and none of the leak fixes or garbage collection techniques work.
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
- …
I’ll keep thinking on this, anyone has any suggestions please feel free to throw them out and I’ll add them to the tests. Right now it’s 12.30am and I’m going to sit and watch Gordon Ramsey and drink a beer.
Edit:
Additional commentary on Ajaxian.com, fingers crossed there is a collective solution soon.
AW’s comment below includes this code…
-
-
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 <= 10000; 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;
-
-
}
-
I’ve added this code to the test suite and it seems to solve the issue !!!
About this entry
You’re currently reading “IE6 Form Tag Orphans,” an entry on jpsykes
- Published:
- 09.19.07 / 11pm
- Category:
- Uncategorized









Comments are closed
Comments are currently closed on this entry.