javascript memory leak

后端 未结 4 1244
名媛妹妹
名媛妹妹 2020-12-28 23:44

I have a some javascript (used with google maps api) that I am testing on IE and Chrome and noticed memory leak symptoms in IE only: when I refresh the page continuously, th

相关标签:
4条回答
  • 2020-12-29 00:16
    • Use JSLint.com to test your code it gives great recommendations about probably problems in your code.
    • There is also a memory leak detector by Microsoft! (It moved here http://www.outofhanwell.com/ieleak/index.php?title=Main_Page , other download and description about the tool called drip: http://www.smallworkarounds.net/2009/04/jquery-leaking-memory-be-careful-while.html)
    • There is also an article by Corckford about mem leaks.
    • jQuery has some build in mechanisms to avoid memory leaks. There are a lot of documentations out there about this problems.
    • Other memory detector by Microsoft
    • Remind: Google announced that they will drop support for IE6.
    • Google Chrome has build in memory profiling (Update on July 2013)

    Update:

    I tested the code above with drip.exe and it seems that there is really something like a memory leak. The memory usage went steadily up while running the code with auto refreshing for some minutes.

    Update 2:

    I think this is the bug: http://code.google.com/p/gmaps-api-issues/issues/detail?id=1555&can=1&q=unload&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars

    0 讨论(0)
  • 2020-12-29 00:20

    Most of the answers so far will help you get there so i am adding a link to an article on IBM Dev Works for Memory leak patterns in JavaScript (you might find it helpful)

    http://www.ibm.com/developerworks/web/library/wa-memleak/

    0 讨论(0)
  • 2020-12-29 00:24

    You need to also execute GUnload before leaving the page. Simply add an "unload" event:

    <body onload="initialize()" onunload="GUnload()">
    

    Read more about this leak at the Google Maps API

    0 讨论(0)
  • 2020-12-29 00:27

    One well-known source of IE memory leaks is the (deliberate or accidental) trapping of Javascript "stuff" in closures (functions) bound as event handlers to DOM elements. Most frameworks try hard to clean out event handlers explicitly for that reason.

    0 讨论(0)
提交回复
热议问题