views:

219

answers:

4

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, the amount of memory used in IE keeps growing (fast), but in Chrome it stays constant. Without posting all of the code (as it is rather long), can I get some suggestions as to what to look out for? What could cause the memory to keep growing like this in IE on page refreshes?

Like I said I know its hard without code, but I'd like to see if any generic advice works first. Thanks.

Update: thanks for the responses so far. As a sanity check, I ran the google maps api "Hello World" code from google to see what would happen in IE (the code is shown below). When running this code in IE, when I keep refreshing the page over and over again, the memory keeps growing and growing. Is this a memory leak? This doesnt seem like intended functionality...

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

Update 2: So is there no way to get this google Hello World map api code to run without leaking memory in IE? I noticed that if I run the same experiment on maps.google.com there doesn't seem to be a leak...It would be great if someone could help me modify the hello world code so that it does not leak in IE; this way I can build off of it (I don't mind using JQuery if this would help, but I tried it on the Hello World code and it was still leaking in IE). Thanks again

+5  A: 

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&amp;can=1&amp;q=unload&amp;colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars

powtac
+1  A: 

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.

Pointy
A: 

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

Andrew
I am using api v3. Thanks for the suggestion though.
hhj
A: 

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/

andreas