Javascript Memory Leaks

Back to the code 🙂 I got assigned to debug a report that the Microsoft Virtual Earth crashes IE6. Unfortunately it took me quite a while to get the environment up to be able properly debug the problem (= I had to install one Windows machine from the scratch). After Googling a while and testing some other tools, I found the IE Memory Leak Detector tool from the MSDN, that looked very promising.

My first step was actually to build a Selenium test case that navigates the map (left-down-right-up in a loop), zooms in and zooms out. Running this test in a loop for 100 times revealed a some differences in memory usage between the browsers. The IE6 started from roughly 58MB, but after a hundred iterations ended up to use 138MB of memory. Opera started to leak actually even faster than IE6, but used only roughly 125MB at the end of the test loop. Finally I tested the FF3.5, that used 88-157MB of memory during the loop, but seemed to garbage collect properly occasionally and it seemed not to leak noticeably.

Finally I got the new Windows test machine equiped with all the drivers, upgraded, activated and installed with Selenium RC, Java and the rest of the tools. Based on the test runs I suspected that the leak must be in our own javascript -code, while googling revealed a number of articles describing how you should set the parameters null after using and the usage of closures. However, the IE Memory Leak Detector gave this kind of reference to code that caused the leak:

function _f1248273915185(){
return {”__type”:”Microsoft.VirtualEarth.Engines.Core.ImageryMetadata.PublicTypes.BirdsEyeSearchResponse”,”Scene”:{”S”:11653832,”O”:0,”Q”:”12012021101″,”RI”:2504,”L”:20,”Fcx”:16,”Fcy”:12,”Hcx”:8,”Hcy”:6,”QA”:0.20479389053054289,”QB”:-11.339952179270028,”QC”:-66060.4659001751,”QD”:0.51723632379069606,”QE”:-27.329727071417665,”QF”:-159324.1954204863,”QG”:0.0086047506233842379,”QH”:-0.45437445343971539,”QI”:-2647.8944163784549,”XA”:-99.125040347204759,”XB”:-40.257039373405007,”XC”:4895.2732690969769,”XD”:-5.057457829331435,”XE”:97.444190848983354,”XF”:-5737.0562779899165,”XG”:0.00054572923124807408,”XH”:-0.016852089141664729,”XI”:1},”ResponseSummary”:{”Copyright”:”Copyright 2009 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.”,”StatusCode”:0,”AuthResultCode”:0,”ErrorMessage”:null,”TraceId”:”5b584e34-1354-4571-85f6-daf69d27f64e|AQ23817″}};}
if(typeof closeDependency !== ’undefined’){closeDependency(’1248273915185’); }

After a bit more googling, I found that this is a response object of a fetching function that seems not to unload properly.  While I was also unable to find a reference to this code (our code seemed to use the SOAP-interface for map loading), this got me to think that the bug could be on the Microsoft’s side of the code. I need to talk to our Javascript gurus :).