Hi,

> Do you have any idea why is this happening?

Well, assuming it _is_ actually happening as opposed to being a
measurement error, I'm afraid not. The thing (again) that I'm not sure
Jose was really clear on was that memory will NOT be freed immediately
just because you stopped referencing it, there's a lag. It looks like
sEIVe helps you know what nodes are still referenced, which is handy,
but I don't know whether it introduces issues (never having used it).

> 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.

Well, it seems like it should be trivial to test each of those. For
instance, you can test with and without `insert`:

    // #1. Original
    var element = new Element("div").insert("test code");

    // #2. Without insert
    var element = new Element("div");
    element.appendChild(document.createTextNode("test code"));

Similarly, getting all of the Prototype stuff out of the way:

    // 3. Without `new Element` or `insert`
    var element = document.createElement("div");
    element.appendChild(document.createTextNode("test code"));

I did a quick test, all I really have time for, and was interested to
see that IE6 takes _dramatically_ longer to do #1 than it does #2
above. Doing #2 above memory use seemed relatively stable.

FWIW,

-- T.J.

On Oct 25, 12:40 pm, Paco Gómez <pacogomezgrana...@gmail.com> wrote:
> 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.

Reply via email to