Ok, so attaching dom elements as properties of
String.prototype.escapeHTML causes leaks. What about keeping them in a
closure?

escapeHTML: (function() {
  var div = document.createElement('div'), text;
  div.appendChild(text = document.createTextNode(''));
  return function() {
    text.data = this;
    return div.innerHTML;
  }
})()

Could you check if that leaks?

Best,
kangax


On May 2, 1:34 pm, ggranum <[EMAIL PROTECTED]> wrote:
> We are seeing a very large memory leak in IE ( 6 7 and 8) when we open
> and close dialog windows from within our application. I narrowed it
> down to the following code change from version 1.5.0 to 1.5.1:
>
> --------------
> if (Prototype.Browser.WebKit || Prototype.Browser.IE)
> Object.extend(String.prototype, {
>   escapeHTML: function() {
>     return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/
> g,'&gt;');
>   },
>   unescapeHTML: function() {
>     return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/
> &gt;/g,'>');
>   }});
>
> // some other code here, unrelated
> /* Begin memory leak for IE */
> Object.extend(String.prototype.escapeHTML, {
>   div:  document.createElement('div'),
>   text: document.createTextNode('')
>
> });
>
> with (String.prototype.escapeHTML) div.appendChild(text);
> /* End memory leak. */
>
> --------------------
>
> Now, in our local version of prototype.js, I simply changed the code
> to the following:
> ------------------------------
> if (Prototype.Browser.WebKit || Prototype.Browser.IE)
> {
>     Object.extend(String.prototype, {
>
>         escapeHTML: function()
>         {
>             return this.replace(/&/g, '&amp;').replace(/</g,
> '&lt;').replace(/>/g, '&gt;');
>         },
>         unescapeHTML: function()
>         {
>             return this.replace(/&amp;/g, '&').replace(/&lt;/g,
> '<').replace(/&gt;/g, '>');
>         }
>     });}
>
> else
> {
>
>     Object.extend(String.prototype.escapeHTML, {
>         div:  document.createElement('div'),
>         text: document.createTextNode('')
>     });
>
>     with ( String.prototype.escapeHTML ) div.appendChild(text);}
>
> ------------------------------------------
>
> If anyone can see a problem with the fix I would love to hear it, as
> we MUST fix this leak. It looked to me like IE is not actually using
> the div and text element trick and is instead using a simple
> replacement expression, so I simply didn't do the div work for IE
> browsers.
>
> The window seems to hold on to all references on page unload. It is
> pretty impressive; an empty window which imported our javascript files
> and prototype would use about 1.2MB on each open/close. In active use
> we see IE at over 500MB in less than half an hour. With the fix, which
> hasn't been heavily tested yet, IE7 hangs out around a hundred megs.
>
> I see this memory leak all the way up to version 1.6.0.2, though I
> have only tested and seen the leak on versions 1.6.0.2, 1.5.1 and
> 1.5.1.2.
>
> Thanks much,
> Geoff Granum
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to