#322 bug
Lea Hayes

Prototype 1.6 - memory leak in new Element() constructor

Reported by Lea Hayes | September 3rd, 2008 @ 11:30 PM | in After 1.7

Hey guys,

I have been experimenting with your library and was curious to find I kept running into memory leaks in Internet Explorer, no problems at all in FireFox.

I created a sample page to reproduce the problem.

A plugin utility for IE7 revealed some memory leaks at the end of each page. I tracked the problem down to the cache within the Element constructor function. By removing the cache I found that the leak dissapeared.

HOWEVER, both the default implementation, and my quick change still result in some major RAM usage in IE only...FireFox works a treat.

//---- The function after my changes (function() { var element = this.Element; this.Element = function(tagName, attributes) {

attributes = attributes || { };
tagName = tagName.toLowerCase();
var cache = Element.cache;
if (Prototype.Browser.IE && attributes.name) {
  tagName = '<' + tagName + ' name="' + attributes.name + '">';
  delete attributes.name;
  return Element.writeAttribute(document.createElement(tagName), attributes);
}

//>>>>>>>>> Here is the small part which I changed.

var tempCache = Element.extend(document.createElement(tagName));
return Element.writeAttribute(tempCache.cloneNode(false), attributes);

}; Object.extend(this.Element, element || { }); }).call(window); //----

I have attached some screen shots which demonstrate the leak; and the sample page which I created to test this. The red dots on the graphs indicate where either the page was initially loaded, or where the button was pressed.

I used "Process Explorer" to monitor IE7 and FF individually.

I am unsure whether this is an error in what I am doing, or yet another difficulty IE7 yields.

Best regards, Lea Hayes

Comments and changes to this ticket

  • John-David Dalton

    John-David Dalton September 4th, 2008 @ 08:32 AM

    • Title changed from “Prototype 1.6 - new Element() constructor” to “Prototype 1.6 - memory leak in new Element() constructor”
  • John-David Dalton
  • John-David Dalton
  • John-David Dalton
  • Tobie Langel

    Tobie Langel October 5th, 2008 @ 12:46 PM

    • State changed from “new” to “bug”
    • Milestone set to 1.7
  • Michal

    Michal October 14th, 2008 @ 11:54 AM

    Leaks is present because new Element() caches created elements into the Element.cache object. However, the cache is not cleaned before page unload, and that is why I am experiencing memory leak (IE6, Windows XP, JavaScript Memory Leak Detector add-in).

    Proposed fix

    Clean Element.cache object on page unload. Modify destroyCache() function to clean the cache:

    
      function destroyCache() {
        for (var id in cache)
          for (var eventName in cache[id])
            cache[id][eventName] = null;
        for(var id in Element.cache)
          Element.cache[id] = null;
      }
    
    • I Added two last lines into function.
  • John-David Dalton
  • Andrew Dupont

    Andrew Dupont October 16th, 2008 @ 10:56 PM

    Nonetheless, we need to consolidate and minimize all the element creation we do inside the library — and make sure they all get cleaned up on page unload.

  • ykphuah

    ykphuah November 4th, 2008 @ 08:39 AM

    I prefer the tool in http://home.wanadoo.nl/jsrosman/ when it comes to debugging memory leaks, the IE plugin just serves as an extra tool to show the element in question.

    Sieve seems to think that your Default2.html test program does not leak!

  • ykphuah

    ykphuah November 4th, 2008 @ 10:14 AM

    Having said the above, I went on to do more testing, and to my amusement, just calling document.createElement will make IE's memory usage shoot up like nobody's business, one hour later, my IE usage is already 700 Meg!

  • John-David Dalton
  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:10 AM

    • Tag changed from dom, element, ie, ie7, leak, needs_benchmarks, needs_patch, needs_tests, tested to element, ie, ie7, needs_benchmarks, needs_patch, needs_tests, section:dom

    [not-tagged:"dom" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:11 AM

    • Tag changed from element, ie, ie7, needs_benchmarks, needs_patch, needs_tests, section:dom to ie, ie7, needs_benchmarks, needs_patch, needs_tests, section:dom

    [not-tagged:"element" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:26 AM

    • Tag changed from ie, ie7, needs_benchmarks, needs_patch, needs_tests, section:dom to ie, ie7, missing:tests, needs_benchmarks, needs_patch, section:dom

    [not-tagged:"needs_tests" tagged:"missing:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:27 AM

    • Tag changed from ie, ie7, missing:tests, needs_benchmarks, needs_patch, section:dom to ie, ie7, missing:benchmarks, missing:tests, needs_patch, section:dom

    [not-tagged:"needs_benchmarks" tagged:"missing:benchmarks" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from ie, ie7, missing:benchmarks, missing:tests, needs_patch, section:dom to ie, ie7, missing:benchmarks, missing:patch, missing:tests, section:dom

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:36 AM

    • Tag changed from ie, ie7, missing:benchmarks, missing:patch, missing:tests, section:dom to ie, ie7, missing:benchmarks, missing:patch, needs:tests, section:dom

    [not-tagged:"missing:tests" tagged:"needs:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from ie, ie7, missing:benchmarks, missing:patch, needs:tests, section:dom to ie, ie7, missing:benchmarks, needs:patch, needs:tests, section:dom

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:39 AM

    • Tag changed from ie, ie7, missing:benchmarks, needs:patch, needs:tests, section:dom to ie, ie7, needs:benchmarks, needs:patch, needs:tests, section:dom

    [not-tagged:"missing:benchmarks" tagged:"needs:benchmarks" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 04:05 AM

    • Tag changed from ie, ie7, needs:benchmarks, needs:patch, needs:tests, section:dom to needs:benchmarks, needs:patch, needs:tests, section:dom

    [not-tagged:"ie" not-tagged:"ie6" not-tagged:"ie7" not-tagged:"ie8" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Andrew Dupont

    Andrew Dupont October 17th, 2010 @ 11:59 PM

    • Milestone changed from 1.7 to After 1.7
    • Assigned user set to “Andrew Dupont”
    • Importance changed from “” to “Low”

    I'm pushing this back to 1.7.1 because (a) I can't trigger a leak in my copy of IE6 (though I do think mine has the leak hotfix applied); (b) we might be doing away with the tag cache altogether, because it's the source of a few other bugs as well.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Attachments

Pages