Skip to content

Commit

Permalink
fix(AgmMap): memory leak when map gets destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
LiadIdan authored and sebholstein committed May 23, 2018
1 parent 078c2a5 commit 6006617
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
ngOnDestroy() {
// unsubscribe all registered observable subscriptions
this._observableSubscriptions.forEach((s) => s.unsubscribe());

// remove all listeners from the map instance
this._mapsWrapper.clearInstanceListeners();
}

/* @internal */
Expand Down
6 changes: 6 additions & 0 deletions packages/core/services/google-maps-api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export class GoogleMapsAPIWrapper {
});
}

clearInstanceListeners() {
this._map.then((map: mapTypes.GoogleMap) => {
google.maps.event.clearInstanceListeners(map);
});
}

setCenter(latLng: mapTypes.LatLngLiteral): Promise<void> {
return this._map.then((map: mapTypes.GoogleMap) => map.setCenter(latLng));
}
Expand Down

0 comments on commit 6006617

Please sign in to comment.