Memory Leaks In Internet Explorer

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Memory Leaks In Internet Explorer - Presentation Transcript

    1. memory leaks in ie understanding the pain
    2. wait! what is a memory leak?
    3. wait! what is a memory leak? "When a system does not correctly manage its memory allocations, it is said to leak memory. A memory leak is a bug . Symptoms can include reduced performance and failure. " -- Douglas Crockford
    4. wait! what is a memory leak?
    5. why internet explorer?
      • IE has 2 separate garbage collectors
      • One for JScript and the other one for the DOM
      • The DOM garbage collector
      • doesn‘t know much about JScript and its quirks!
    6. so, it‘s all about garbage collecting?
    7. so, it‘s all about garbage collecting?
    8. … and how exactly do memory leaks in JScript happen?
    9. main cause: Circular References (attention! buzzword!)
    10. let‘s code a memory leak!
    11. let‘s code a memory leak! // This will approx add 1 MB of memory if executed 1000 times // …each reload! var el = document.createElement("div"); var fnOver = function(e) {     el.innerHTML = "Mouse over!"; }; el.onmouseover = fnOver; document.getElementsByTagName("body")[0].appendChild(el); // Removes the element, but it‘s still in the memory el.parentNode.removeChild(el);
    12. where‘s the … uhm … circular whatever?! // This will approx add 1 MB of memory if executed 1000 times // …each reload! var el = document.createElement("div"); var fnOver = function(e) {     el.innerHTML = "Mouse over!"; }; el.onmouseover = fnOver; document.getElementsByTagName("body")[0].appendChild(el); // Removes the element, but it‘s still in the memory el.parentNode.removeChild(el);
    13. ah, there it is! // This will approx add 1 MB of memory if executed 1000 times // …each reload! var el = document.createElement("div"); var fnOver = function(e) {     el .innerHTML = "Mouse over!"; }; el .onmouseover = fnOver ; document.getElementsByTagName("body")[0].appendChild(el); // Removes the element, but it‘s still in the memory el.parentNode.removeChild(el);
    14. explanation " Memory leaks related to event handlers are, generally speaking, related to enclosures. In other words, attaching a function to an event handler which points back to its element can prevent browsers from garbage-collecting either. " -- Some guy in some forum
    15. explanation " Memory leaks related to event handlers are, generally speaking, related to enclosures. In other words, attaching a function to an event handler which points back to its element can prevent browsers from garbage-collecting either. " -- Some guy in some forum Circular Reference!
    16. workaround
    17. workaround Let‘s build our own garbage collector!
    18. the &quot;purger&quot; function purge(d) { var a = d.attributes, i, l, n; if (a) { for (i=0, l=a.length; i<l; i++) { n = a[i].name; if (typeof d[n] === 'function') { d[n] = null; } } } a = d.childNodes; if (a) { for (i=0, l=a.length; i<l; i++) { purge(d.childNodes[i]); } } }
    19. what does it do? &quot;The purge function takes a reference to a DOM element as an argument. It loops through the element's attributes. If it finds any functions, it nulls them out. This breaks the cycle, allowing memory to be reclaimed . It will also look at all of the element's descendent elements, and clear out all of their cycles as well &quot; -- http://javascript.crockford.com/memory/leak.html
    20. our memory leak: fixed. var el = document.createElement(&quot;div&quot;); var fnOver = function(e) {     el.innerHTML = &quot;Mouse over!&quot;; }; el.onmouseover = fnOver; document.getElementsByTagName(&quot;body&quot;)[0].appendChild(el); // Run our garbage collector purge(el); // Removes the element el.parentNode.removeChild(el);
    21. ajax libraries and memory leaks
      • Ajax libraries reduce the pain
      • Element storage and event clearing onunload
      • Nevertheless Prototype contains several critical memory leaks – Patches are available
      • Always check bug trackers and communities
      • before deciding which ajax library to use.
    22. memory leak detection Windows Task Manager Drip ( http://tinyurl.com/drip-drip ) JavaScript Memory Leak Detector ( http://tinyurl.com/jmld-tool )
    23. references http://msdn.microsoft.com/en-us/library/bb250448.aspx http://stackoverflow.com/questions/491527/javascript-event-handlers-always-increase-browser-memory-usage http://javascript.crockford.com/memory/leak.html
    24. thanks Christopher Blum, XING AG

    + CHristopher BlumCHristopher Blum, 5 months ago

    custom

    709 views, 0 favs, 0 embeds more stats

    More info about this document

    CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

    Go to text version

    • Total Views 709
      • 709 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 5
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories