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.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

1 Favorite

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
    • Problem: The DOM garbage collector
    • doesn‘t know much about JScript and its references!
  6. which versions are affected?
    • All versions below IE 8
    • No known memory leak in version 8 (yes, I googled it)
  7. so, it‘s all about garbage collecting?
  8. so, it‘s all about garbage collecting?
  9. … and how exactly do memory leaks in JScript happen?
  10. main cause: Circular References (attention! buzzword!)
  11. let‘s code a memory leak using a circular reference! // 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 the Prototype Library contains several critical memory leaks – Patches are available
    • Always check bug trackers and core groups
    • 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. more informations and leaks 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

+ CHristopher BlumCHristopher Blum, 5 months ago

custom

1164 views, 1 favs, 6 embeds more stats

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1164
    • 1031 on SlideShare
    • 133 from embeds
  • Comments 1
  • Favorites 1
  • Downloads 21
Most viewed embeds
  • 119 views on http://blog.xing.com
  • 9 views on http://matrix.kwick.de
  • 2 views on http://www.netvibes.com
  • 1 views on http://feeds.feedburner.com
  • 1 views on http://electronicasamaria.blogspot.com

more

All embeds
  • 119 views on http://blog.xing.com
  • 9 views on http://matrix.kwick.de
  • 2 views on http://www.netvibes.com
  • 1 views on http://feeds.feedburner.com
  • 1 views on http://electronicasamaria.blogspot.com
  • 1 views on http://blog.openbc.com

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