infusion-code / angular-maps

Angular Maps (X-Map) is a set of components and services to provide map functionality in angular 2+ apps. X-Maps architecture is provider independent and can be used with Bing, Google, ESRI or any other service enabled mapping provider. X-Map contains a default implementation for Bing Maps.
MIT License
41 stars 34 forks source link

Memory leak with bing maps #94

Open jdiekhoff opened 5 years ago

jdiekhoff commented 5 years ago

I'm using this library to show live changes to marker pins. I've re-created the issue using the bing basic map from stackblitz. This sample updates the marker list every 3 seconds:

StackBlitz

You can see the effects running the profiler. It appears that previous markers are not being released appropriately. IncreasingMemoryUsage

METACEO commented 5 years ago

Thanks @jdiekhoff, the StackBlitz example is a great help. I think we need to capture the handler ids of the events we're attaching to the Bing markers and remove/detach them within every marker's DeleteMarker call.

See the JavaScript example in the Microsoft's docs here:

//Attach an event
var handlerId = Microsoft.Maps.Events.addHandler(target, 'eventName', handler);

//Remove an event
Microsoft.Maps.Events.removeHandler(handlerId);

My initial hunch is that these event handlers are not being detached and are not allowing the old markers from being garbage collected.

thor-schueler commented 5 years ago

@METACEO : Are you on the hook for a pull request?