javascript内存泄漏 [英] javascript memory leak

查看:107
本文介绍了javascript内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些javascript(与谷歌地图api一起使用),我正在IE和Chrome上测试,并且只注意到IE中的内存泄漏症状:当我连续刷新页面时,IE中使用的内存量不断增长(快速) ),但在Chrome中它保持不变。如果没有发布所有代码(因为它很长),我可以得到一些关于要注意什么的建议吗?什么可能导致内存在页面刷新时在IE中保持这样的增长?

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.

更新:感谢目前为止的回复。作为一个完整性检查,我运行了谷歌地图apiHello World代码谷歌看看IE中会发生什么(代码如下所示)。在IE中运行此代码时,当我一遍又一遍地刷新页面时,内存会不断增长和增长。这是内存泄漏吗?这似乎不是预期的功能......

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>

更新2 :所以没有办法获得这个谷歌Hello World映射api代码在IE中运行而不泄漏内存?我注意到,如果我在 maps.google.com 上运行相同的实验,则似乎没有泄漏。 ..如果有人可以帮我修改你好的世界代码以便它不会在IE中泄漏,那将会很棒。这样我可以构建它(我不介意使用JQuery,如果这会有所帮助,但我在Hello World代码上尝试了它,它仍然在IE中泄漏)。再次感谢

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

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆