简体   繁体   English

Openlayers 3 - 如何垃圾收集 Canvas ReplayGroup 对象?

[英]Openlayers 3 - How to garbage collect Canvas ReplayGroup objects?

I've got an issue with ol.render.canvas.ReplayGroup objects not being let go to garbage collection.我遇到了 ol.render.canvas.ReplayGroup 对象没有进入垃圾收集的问题。

The layer that this is for is an ol.layer.Image, created from an ol.source.ImageVector, in turn created from an ol.source.Vector source.这是用于的层是一个 ol.layer.Image,从 ol.source.ImageVector 创建,反过来从 ol.source.Vector 源创建。

The sequence of events that I'd like to have result in some garbage collection is, the Image's style is set to null with setStyle(null);我希望导致垃圾收集的事件序列是,使用 setStyle(null) 将图像的样式设置为 null; then the Image's source is set to null with setSource(null);然后使用 setSource(null) 将图像的源设置为 null; then the ol.layer.Image object is removed from the map with setMap(null);然后使用 setMap(null) 从地图中删除 ol.layer.Image 对象;

This does result in the layer being removed from the map ( I think, it disappears ), but when I profile the web page with Chrome's heap allocation profile, the canvas.ReplayGroup object is still there, never to be used again.这确实导致图层从地图中删除(我认为它消失了),但是当我使用 Chrome 的堆分配配置文件分析网页时,canvas.ReplayGroup 对象仍然存在,永远不会再次使用。

Is this something anyone else has run into?这是其他人遇到的事情吗? I've tried to use the map.addLayer() instead of layer.setMap( ), same results.我尝试使用 map.addLayer() 而不是 layer.setMap(),结果相同。

== edit == == 编辑 ==

I forgot to write, the ol.layer.Image has been added to an ol.layer.Group.忘记写了,ol.layer.Image 已经添加到ol.layer.Group 中了。 More specifically, that last part above was map.addLayer( group ) and also group.getLayers().forEach(function(l){ l.setMap(map); }), no difference it seems.更具体地说,上面的最后一部分是 map.addLayer( group ) 和 group.getLayers().forEach(function(l){ l.setMap(map); }),看起来没有区别。

https://github.com/openlayers/ol3/blob/master/src/ol/source/imagevectorsource.js https://github.com/openlayers/ol3/blob/master/src/ol/source/imagevectorsource.js

In the ol.source.ImageVector that's the source for the ol.layer.Image, I found a reference to the replay group classes called replayGroup_.在作为 ol.layer.Image 源的 ol.source.ImageVector 中,我找到了对名为 replayGroup_ 的重放组类的引用。 Setting that 'private' property to null after setting the layer source to null results in garbage collection.. yay!在将图层源设置为 null 后将“私有”属性设置为 null 会导致垃圾收集..耶!

var imageVector = layer.getSource();
layer.setSource(null);
imageVector.setStyle(null);
imageVector.replayGroup_ = null;
imageVector = null;

This works for me for now这现在对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM