fixed memory leak in Marker.js. With manual test. p=rcoup, r=me (closes #2258)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9754 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -78,7 +78,6 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
this.icon.offset = newIcon.offset;
|
||||
this.icon.calculateOffset = newIcon.calculateOffset;
|
||||
}
|
||||
this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -94,9 +93,6 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
|
||||
this.map = null;
|
||||
|
||||
this.events.destroy();
|
||||
this.events = null;
|
||||
|
||||
if (this.icon != null) {
|
||||
this.icon.destroy();
|
||||
this.icon = null;
|
||||
@@ -115,6 +111,9 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
* location passed-in
|
||||
*/
|
||||
draw: function(px) {
|
||||
if (!this.events) {
|
||||
this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
|
||||
}
|
||||
return this.icon.draw(px);
|
||||
},
|
||||
|
||||
@@ -126,6 +125,10 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
if (this.icon != null) {
|
||||
this.icon.erase();
|
||||
}
|
||||
if (this.events) {
|
||||
this.events.destroy();
|
||||
this.events = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
60
tests/manual/memory/Marker-2258.html
Normal file
60
tests/manual/memory/Marker-2258.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Memory Test - Layer.Markers / Marker</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
p {
|
||||
padding-top: 1em;
|
||||
}
|
||||
#map {
|
||||
width: 256px;
|
||||
height: 256px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="../../../lib/Firebug/firebug.js"></script>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
var map, layer, marker;
|
||||
|
||||
function init(){
|
||||
map = new OpenLayers.Map('map');
|
||||
map.addLayer(new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ));
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
|
||||
layer = new OpenLayers.Layer.Markers( "Markers" );
|
||||
map.addLayer(layer);
|
||||
|
||||
marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0));
|
||||
layer.addMarker(marker);
|
||||
|
||||
window.setTimeout(function() {
|
||||
layer.removeMarker(marker);
|
||||
layer.addMarker(marker);
|
||||
|
||||
// people SHOULD call marker.destroy(). But if they don't
|
||||
// we leak memory.
|
||||
//marker.destroy();
|
||||
|
||||
window.alert("Setup - hit STOP in the leak detector now");
|
||||
}, 100);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1 id="title">Memory Test - Layer.Markers / Marker</h1>
|
||||
<pre id="status"></pre>
|
||||
<div id="map"></div>
|
||||
<p>
|
||||
This test is a memory leak test for usage of Layer.Markers / Marker.
|
||||
</p>
|
||||
<p>
|
||||
Run this test in IE6/7 with <a href="http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector-v2.aspx">JavaScript Memory Leak Detector v2</a>
|
||||
and watch it identify a leak unless this is fixed.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user