Nick Mudge Ignition Software Consulting & Development

I'm writing a program right now using Javascript. Had an interesting bug where some code would work in Firefox sometimes and sometimes it wouldn't. I added a style property to a browser DOM object to store color information. The property was global. What happened was that every once in awhile it would seem that the property would disappear.

That was exactly what was happening. The property would disappear out of thin air. It was global though, so how could this be? Well there are two garbage collection mechanisms going on, from what I can tell. There's Javascript's garbage collection, garbaging up pure Javascript code. But the objects created with the DOM are garbage collected by the browser. And the browser doesn't clean up exactly the same way Javascript does. It appears that Firefox will sometimes garbage global DOM variables. I think that was what happening, Firefox was sometimes deleting the extra property I added to the DOM object.

The fix was instead of adding a property to a DOM object, I just created a normal Javascript global variable and used that. Actually it's a little more complicated than that. I was adding the property to many different DOM objects in a loop. So the solution I implemented was creating many normal Javascript global variables in a loop and using them.

I realized what was happening from reading A re-introduction to JavaScript. It says:

Browser hosts need to manage a large number of objects representing the HTML page being presented - the objects of the DOM. It is up to the browser to manage the allocation and recovery of these.

Comments

Name: (required)
Email: (required)
Website:
What has four legs, rhymes with bat and says, "Meow?" (One word answer.)
Spam Filter: