Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Bing映射V8 JS API内存泄漏问题_Javascript_Memory Leaks_Bing Maps - Fatal编程技术网

Javascript Bing映射V8 JS API内存泄漏问题

Javascript Bing映射V8 JS API内存泄漏问题,javascript,memory-leaks,bing-maps,Javascript,Memory Leaks,Bing Maps,概述:我一直在从事的这个项目接收来自外部来源的消息,并根据收到的信息更新Bing地图。然而,当我让页面长时间运行时,页面最终会耗尽所有内存并自行崩溃 详细信息:这是在我从谷歌地图切换到Bing地图后出现的,无论我怎么尝试都无法解决。我到处搜索,试图通过Bing地图最佳实践解决这个问题,或者至少找到导致这个问题的原因,但我一直找不到任何真正解决这个问题的方法 我有大量的数据,并试图使用谷歌Chrome的控制台更仔细地分析它们,但都没有成功 尝试的修复: 将处理程序添加到map初始化函数中(如下所

概述:我一直在从事的这个项目接收来自外部来源的消息,并根据收到的信息更新Bing地图。然而,当我让页面长时间运行时,页面最终会耗尽所有内存并自行崩溃

详细信息:这是在我从谷歌地图切换到Bing地图后出现的,无论我怎么尝试都无法解决。我到处搜索,试图通过Bing地图最佳实践解决这个问题,或者至少找到导致这个问题的原因,但我一直找不到任何真正解决这个问题的方法

我有大量的数据,并试图使用谷歌Chrome的控制台更仔细地分析它们,但都没有成功

尝试的修复:

  • 将处理程序添加到map初始化函数中(如下所示),但这似乎并没有改善多少
  • 从地图初始化功能加载任何Bing地图模块(如下所示)。这相当大程度上清理了代码,但似乎对内存使用没有太大影响
  • 同步加载地图。然而,这似乎打破了与网站上Bing地图有关的一切
  • 在收到消息时停止处理映射。这有助于键的使用,但对内存的使用并没有帮助
相关代码:


以下是地图初始化函数(通过HTML中的Bing地图调用异步运行):


以下是收到消息后运行的函数:

function redraw(payload) {

// If the user is does not have the page active, the payload is refused
if (!acceptingPayloads) {
    return false;
}

let location = new Microsoft.Maps.Location(payload.message.lat, payload.message.lng);
let name = payload.message.name;
let dest = payload.message.dest;
let mph = payload.message.mph;

const STP = new Microsoft.Maps.Location(44.9416428, -93.1917952);
const MPLS = new Microsoft.Maps.Location(44.9747502, -93.2774464);

if (dest.toUpperCase() === "S") {
    dest = {letter: "S", name: "St. Paul", coords: STP};
} else if (dest.toUpperCase() === "M") {
    dest = {letter: "M", name: "Minneapolis", coords: MPLS};
} else {
    dest = null;
}

console.log(name + ": " + location.latitude + ", " + location.longitude + " - " + dest.name + " - " + mph + " mph");

// Gets the bus object that the payload was sent from
currentBus = getCurrentBus(name);

// Removes the timeout for the current bus
if (currentBus.timeout !== null) {
    clearTimeout(currentBus.timeout);
}

currentBus.location = location;
currentBus.destination = dest;
currentBus.mph = mph;
currentBus.time = Date.now();
currentBus.name = name;

// Restart the timeout for the current bus
beginTimeout();

// Calculate the distance between the current bus and its destination
calcDistToDest();

$("." + currentBus.assignment + "-item").css('display', 'block')
}

最后,这里是我用来获取点之间距离的函数:

function calcDistToDest() {

// Clear all information from the Directions Manager
currentBus.polylineRender.clearAll();

// Set Route Mode to driving and the render options
currentBus.polylineRender.setRequestOptions({
    routeMode: Microsoft.Maps.Directions.RouteMode.driving
});
currentBus.polylineRender.setRenderOptions({
    autoUpdateMapView: false,
    drivingPolylineOptions: {
        visible: POLYLINE_VISIBILITY
    },
    waypointPushpinOptions: {
        visible: false
    },
    firstWaypointPushpinOptions: {
        anchor: currentBus.pin.getAnchor(),
        icon: currentBus.pin.getIcon(),
        title: currentBus.pin.getTitle(),
        text: currentBus.pin.getText()
    }
});

// Sets the waypoint of the bus's current position and destination
currentBus.polylineRender.addWaypoint( new Microsoft.Maps.Directions.Waypoint({
    location: currentBus.location
}));
currentBus.polylineRender.addWaypoint( new Microsoft.Maps.Directions.Waypoint({
    location: currentBus.destination.coords
}));

// Calculate the directions
currentBus.polylineRender.calculateDirections();
}

基本上,我所寻找的是一种方法,找出问题的原因,如果问题简单,我只是缺少一些明显的东西,或者一开始就避免这个问题的最佳实践,那么就是一个实际的解决方案


注意:我很抱歉发布了这么多代码。很难确定要发布什么代码,因为我不知道代码的哪个部分导致了问题。如果需要修改或需要任何其他信息,请告知我,我很乐意效劳。我还从同一个文件中遗漏了许多看似无关的JS代码,如果需要,我很乐意添加这些代码。

内存泄漏主要是通过实现Bing地图的实验分支解决的,正如

下面是如何使用实验分支导入Bing地图的示例:

<script src='https://www.bing.com/api/maps/mapcontrol?branch=experimental&callback=[Insert callback function]' async defer></script>


后来,我能够切换回release分支,因为内存泄漏的修复被推送到该分支。有关Bing地图控制分支的更多信息,请参见

您使用的是Bing地图V8的哪个分支?冻结的分支已经有一年多没有更新了,并且有很多已知的内存泄漏,其中很多都在主发布分支中修复。在实验分支中还有几个修复程序。你在使用哪个浏览器,我相信你报告的问题是IE的已知问题。所以我一直在使用发布分支。这个问题在Chrome、Firefox、IE和Edge上似乎以同样的速度出现。你能试试实验分支看看这个问题是否仍然存在。如果问题已经解决,那么它可能会在下周(如果它及时发布的话)或者在9月底之前出现在主发布分支中。
<script src='https://www.bing.com/api/maps/mapcontrol?branch=experimental&callback=[Insert callback function]' async defer></script>