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"></script>
<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
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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With