[OpenLayers-Users] Markers' events memory leak?
Donal
donal_regan10 at YAHOO.CO.UK
Fri Feb 16 00:29:11 EST 2007
I hope that some might find this useful.
I found the following function at http://dev.rubyonrails.org/ticket/5198
// Remove all event handlers from an element
stopObservingElement: function (element) {
if (! Event.observers) return;
for (var i = 0; i < Event.observers.length; ) {
if (element == Event.observers[i][0]) {
Event.stopObserving.apply (this, Event.observers[i]);
Event.observers.splice (i, 1);
}
else
i++;
}
}
I added this function to the OpenLayers.Event class.
I now can call OpenLayers.Event.stopObservingElement(this.imageDiv); in the
icon destroy() method and the memory leak is kept in check.
Cheers,
Donal
Donal wrote:
>
> Hello,
>
> I have a GeoRSS layer which displays a number of icons equal to the value
> of a select box e.g. 10,25,50,100.
> When the select box changes value, the GeoRSS layer is destroyed and a new
> layer is displayed with the new number of icons. I notice in IE 6 that the
> memory used steadily increases as I repeatedly change (up and down) the
> value in the select box.
>
> I see that when a marker is initialized, BROWSER_EVENTS are attached to
> the marker's element (this.icon.imageDiv) with a call to
> OpenLayers.Event.observe(element,eventType,this.handleBrowserEvent.bindAsEventListener(this));
> in Events.js attachToElement() function.
>
> If I comment out the call to attachToElement, the memory used stays fairly
> constant as I change the select box value (but obviously my markers have
> no events associated with them which isn't much use). This suggests to me
> that events not being detached/removed properly are the cause of the leak.
>
> So I want to try something like
>
> OpenLayers.Event.stopObserving(this.icon.imageDiv, "mouseover", observer);
>
> for each of the BROWSER_EVENTS as the markers are destroyed but I am not
> sure what I should put as the value for observer.
>
> I have tried
>
> adding the following propeties to the Events object
>
> this.obs_handles = new Object();
> this.obs_handles[element] = new Array();
>
> and then in attachToElement doing
>
> this.obs_handles[element][eventType] =
> this.handleBrowserEvent.bindAsEventListener(this);
> OpenLayers.Event.observe(element, eventType,
> this.obs_handles[element][eventType]);
>
> and then in Markers.destroy() adding
>
> OpenLayers.Event.stopObserving(this.icon.imageDiv,"mouseover",this.events.obs_handles[this.icon.imageDiv]["mouseover"]);
> OpenLayers.Event.stopObserving(this.icon.imageDiv,"mouseout",this.events.obs_handles[this.icon.imageDiv]["mouseout"]);
> OpenLayers.Event.stopObserving(this.icon.imageDiv,"mousedown",this.events.obs_handles[this.icon.imageDiv]["mousedown"]);
> etc;
>
> this.events.obs_handles[this.icon.imageDiv] = null;
> this.events.obs_handles = null;
>
> but this has no effect.
>
> Am I barking up the wrong tree? Any help/advice will be gratefully
> received.
>
> Thanks,
>
> Donal
>
>
--
View this message in context: http://www.nabble.com/Markers%27-events-memory-leak--tf3232599.html#a8999174
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list