dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
197 stars 47 forks source link

Memory Leaks #3

Closed MatthieuBarthel closed 11 years ago

MatthieuBarthel commented 11 years ago

Hi,

I work on an one page application built on Angular and it uses a lot of maps.

My issue is that every time I instantiate a new map it will consume some memory that won't be released.

I measured the following with Chrome Web Inspector's Timeline: loading a map 100 times made the memory grow from 23MB to 160MB.

The issue is not directly related the angular-gm, but I don't see Google fixing that any time soon. The only fix I imagine is to instantiate a map and reuse it, it means that we need to be able to "rescue" it before Angular destroys the DOM, then "reset" and re-inject it later when another map is called.

Does anybody has that memory issue ?

dylanfprice commented 11 years ago

Hi Matthiue,

Thanks for bringing this up. For anyone else who's interested, here's some more info: http://stackoverflow.com/questions/10485582/what-is-the-proper-way-to-destroy-a-map-instance

I can try something similar to your idea and let you know how it goes.

MatthieuBarthel commented 11 years ago

Hi dylanfprice,

Thanks for your reply, I worked on it and came up with a proof of concept : http://plnkr.co/edit/zxhJgOQEhPxPAX9AUCGs?p=preview

The rescue/reuse technique gives good results, tell me what you think and if I can help you for something.

dylanfprice commented 11 years ago

Cool thanks for doing that. I will have some time to add this in at the end of this week.

MatthieuBarthel commented 11 years ago

That's awesome thanks a lot, I'm looking forward for your release :+1:

dylanfprice commented 11 years ago

I got your basic idea working and put it in a separate branch: https://github.com/dylanfprice/angular-gm/tree/memory-leak-fix

It's not quite ready yet because I need to deal with a few issues like refreshing stale markers on the map.

I went ahead and put a build of the memory-leak-fix branch up: http://dylanfprice.github.io/angular-gm/angular-gm-0.1.0-memory-leak-fix.js. Let me know if that solves your memory leak and I'll fix those remaining issues!

MatthieuBarthel commented 11 years ago

Your are awesome, thank you !

I did an automated memory test, going through 300 views during 5 minutes, each view got a map, and here are the results:

Do not hesitate if I can do anything to help you.