Hi TJ, I'm Jose's partner. The thing I don't understand is why we can recover memory after creating any other kind of object, but not with DOM elements. For example, this memory is recovered after destroying the object: (http://pastie.org/1247004) var TestClass = Class.create({ initialize: function() { this.options = { bigString: new Array(1000).join(new Array(3000).join("XXXXX")) }; }, destroy: function() { alert('before destroy'); this.options = null; alert('after destroy'); } });
function execute2(){ var myObject = new TestClass(); myObject.destroy(); } But the same code, trying to destroy Element objects is not working in some cases. Example 1: memory is recovered when using new Element and not inserting anything inside: (http://www.pastie.org/1247025) var TestClass = Class.create({ initialize: function() { this.options = { array: $A() }; for(var i=0; i<3000; i++){ var element = new Element("div"); this.options.array.push(element); } }, destroy: function() { alert('before destroy'); for(var i=0; i<this.options.array.size(); i++){ this.options.array[i]=null; } delete this.options.array; delete this.options; alert('after destroy'); } }); By the way, it doesn't matter if we nullify every element in the array or not, as you said before. That's a good thing to know :-) In this example we recover only half of the memory, but that's not a problem. If we execute this same code some more times this "extra" memory doesn't increase. We test these things using sIEve (http://home.orange.nl/jsrosman/). We can see there that the number of DOM nodes that are being used is back to normal after destroying the object. Example 2 (http://www.pastie.org/1247055): memory is NOT recovered: var TestClass = Class.create({ initialize: function() { this.options = { array: $A() }; for(var i=0; i<3000; i++){ var element = new Element("div").insert("test code"); this.options.array.push(element); } }, destroy: function() { alert('before destroy'); for(var i=0; i<this.options.array.size(); i++){ this.options.array[i]=null; } delete this.options.array; delete this.options; alert('after destroy'); } }); function execute2(){ var myObject = new TestClass(); myObject.destroy(); } Here the only difference is that the nodes we insert have text inside: var element = new Element("div").insert("test code"); Now we can see that memory is not freed, and that the number of nodes used after being destroyed is 6000. (they are not being freed, like if something was referencing them). Do you have any idea why is this happening? I believe that if we at least can free this nodes in this simple example we could understand why they are not being freed in our big application. I'm guessing that it could be related to: - Something in the initialize of element class (we add the element to some cache) - Something in the insert method - References that are being stored in each element (to its parent and child nodes) make it impossible for IE to remove them from memory. Again, thanks a lot for your help! Kind regards, Paco -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.