Memory leak when clusters are frequently redrawn
Closed this issue · 1 comments
GoogleCodeExporter commented
Version: 2.0.9
I have created simple map dashboard which shows currently active customers.
When customer connects new marker is added to the clusterer and when customer
disconnects marker is removed from it.
In order to display this changes marker clusterer are redrawn every second.
Memory leak related to fix for Issue 157
In ClusterIcon.onAdd method listener for "bounds_changed" event is created, but
never cleared after in onRemove function
Solution/Workaround:
1 Add property to save listener reference in it (boundsChangedListenerRef_) to
ClusterIcon
function ClusterIcon(cluster, styles) {
cluster.getMarkerClusterer().extend(ClusterIcon, google.maps.OverlayView);
this.cluster_ = cluster;
this.styles_ = styles;
this.center_ = null;
this.div_ = null;
this.sums_ = null;
this.visible_ = false;
this.boundsChangedListenerRef_ = null; // Property for "bounds_changed" event listener reference
this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
}
2 In ClusterIcon.onAdd method save reference to newly created listener
// Fix for Issue 157
if (this.boundsChangedListenerRef_) {
google.maps.event.removeListener(this.boundsChangedListenerRef_);
}
this.boundsChangedListenerRef_ = google.maps.event.addListener(this.getMap(), "bounds_changed", function () {
cDraggingMapByCluster = cMouseDownInCluster;
});
3 In ClusterIcon.onRemove method remove listener, which is not necessary anymore
if (this.boundsChangedListenerRef_) {
google.maps.event.removeListener(this.boundsChangedListenerRef_);
this.boundsChangedListenerRef_ = null;
}
Original issue reported on code.google.com by Andrejs.Bedenko
on 6 Jan 2014 at 3:25
- Merged into: #265
GoogleCodeExporter commented
This is fixed in issue 265 and is fixed in release 2.0.16 of marker clusterer
plus, but I would recommend using the latest, release 2.1.2.
Original comment by brett.mc...@gmail.com
on 20 Feb 2014 at 1:57
- Changed state: Duplicate