nomo-kazza / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
Apache License 2.0
0 stars 0 forks source link

Memory leak when clusters are frequently redrawn #286

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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