OpenLayers OpenLayers

Ticket #510 (closed bug: fixed)

Opened 2 years ago

Last modified 1 year ago

Marker Memory Leak

Reported by: euzuro Assigned to: euzuro
Priority: major Milestone: 2.4 Release
Component: Marker Version: 2.3
Keywords: Cc: james@sandfordtechnology.com
State:

Description

split from #369

If we don't unregister event handlers from the marker, they do not get garbage collected, and this is a very unfortunate memory leak.

the patch, originally from #369, fixes this by unregistering the listeners.

Attachments

stopObserving.patch (2.9 kB) - added by euzuro on 02/28/07 02:13:18.
this is a cleaned up version of the patch with an included test
510-2.patch (2.4 kB) - added by sderle on 03/21/07 02:55:42.
Patch to several classes to call this.events.destroy() as needed
510-1.patch (4.4 kB) - added by sderle on 03/21/07 04:41:03.
Add removeFromElement() to Events, and add destroy() that calls it. Includes tests, and clean up in Event.stopObserving() that makes the tests work. This rendition of the patch doesn't cause errors when the map is destroyed.
510-1.uz.patch (6.0 kB) - added by euzuro on 03/23/07 10:18:27.
some small modifications to original patch. removed old prototype line that nullifies (instead of removing) the entry from the observers list (this will raise errors otherwise) and slightly recoded the logic of the entry removal. should be good to go. prease to reviewing
context.patch (0.7 kB) - added by euzuro on 03/23/07 13:27:36.
i thought i was making things cleaner by declaring the var observer = this.observers[i]; but it turns out, not the case. the declaration of that observer was overriding the function's parameter 'observer', and therefore, events were not getting unregistered. seems to me like context rules should prevent that from happening. but whatever. this fixes it. apologies.
observer_cache2.patch (5.4 kB) - added by euzuro on 03/23/07 22:37:42.
this is a patch based on a suggestion sent to the dev list by James. We need a CCLA or ICLA to commit it, but it has my approval. Only thing I've added is some formatting and the updating of the tests so they dont break.

Change History

02/28/07 02:13:18 changed by euzuro

  • attachment stopObserving.patch added.

this is a cleaned up version of the patch with an included test

02/28/07 02:45:15 changed by euzuro

on second thought through this ticket, however, it becomes readily apparent to me that the real, complete, and elegant solution to this problem is simply to create a destroy() method on the OpenLayers.Events class that is in charge of cycling through its list of listeners and unregistering them all. Then all you have to do is in the Marker destroy, you call

this.events.destroy() this.events = null;

which is the way this whole thing is supposed to work.

so there you go. I would make the new patch myself but it's getting on 2 in the morning and it would involve writing test cases too which is just way beyond reasonable at this hour.

03/21/07 02:55:42 changed by sderle

  • attachment 510-2.patch added.

Patch to several classes to call this.events.destroy() as needed

03/21/07 04:06:46 changed by sderle

  • keywords set to review.
  • owner set to sderle.
  • status changed from new to assigned.

Please review. Patch 510-1 and 510-2 can be applied as separate commits.

03/21/07 04:07:40 changed by sderle

Note, 510-1 and 510-2 supersede stopObserving.patch.

03/21/07 04:41:03 changed by sderle

  • attachment 510-1.patch added.

Add removeFromElement() to Events, and add destroy() that calls it. Includes tests, and clean up in Event.stopObserving() that makes the tests work. This rendition of the patch doesn't cause errors when the map is destroyed.

03/23/07 10:18:27 changed by euzuro

  • attachment 510-1.uz.patch added.

some small modifications to original patch. removed old prototype line that nullifies (instead of removing) the entry from the observers list (this will raise errors otherwise) and slightly recoded the logic of the entry removal. should be good to go. prease to reviewing

03/23/07 10:24:35 changed by sderle

  • status changed from assigned to closed.
  • resolution set to fixed.

applied as r2867.

03/23/07 11:08:01 changed by euzuro

  • status changed from closed to reopened.
  • resolution deleted.

forgot to do patch 510-2 -- need to do the actual destroying :-)

patch forthcoming

03/23/07 11:13:46 changed by openlayers

  • cc set to james@sandfordtechnology.com.

03/23/07 13:27:36 changed by euzuro

  • attachment context.patch added.

i thought i was making things cleaner by declaring the var observer = this.observers[i]; but it turns out, not the case. the declaration of that observer was overriding the function's parameter 'observer', and therefore, events were not getting unregistered. seems to me like context rules should prevent that from happening. but whatever. this fixes it. apologies.

03/23/07 14:02:19 changed by sderle

  • keywords changed from review to commit.
  • owner changed from sderle to euzuro.
  • status changed from reopened to new.

context patch looks good. please apply.

03/23/07 21:35:43 changed by euzuro

context.patch applied with r2873

03/23/07 21:38:13 changed by euzuro

  • keywords changed from commit to review.

03/23/07 21:57:53 changed by euzuro

the 510-2.patch is good but i have separated it out into a separate ticket (#558)

03/23/07 22:00:09 changed by euzuro

I would close this ticket right now, except for the fact that a very nice member of our community has noticed that the changes we've made here make it painfully slow to remove markers. clearly we can't have that. i'll attach his patch and give it my seal of approval. we need his ICLA / CCLA before it can be incorporated, though.

03/23/07 22:37:42 changed by euzuro

  • attachment observer_cache2.patch added.

this is a patch based on a suggestion sent to the dev list by James. We need a CCLA or ICLA to commit it, but it has my approval. Only thing I've added is some formatting and the updating of the tests so they dont break.

03/23/07 22:38:22 changed by euzuro

Ok. I have added patch version of James's suggestion. If we can get his approval for the code, please review and commit this.

03/26/07 13:34:03 changed by euzuro

  • status changed from new to closed.
  • resolution set to fixed.

great patch. added with r2896. thanks james!

07/05/07 17:03:18 changed by euzuro

  • keywords deleted.