{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1538","labels_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1538/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1538/comments","events_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1538/events","html_url":"https://github.com/angular-ui/angular-google-maps/issues/1538","id":108986562,"number":1538,"title":"Google Map instance leaks when directive used on different ui-router states","user":{"login":"chris-armstrong","id":11450231,"avatar_url":"https://avatars.githubusercontent.com/u/11450231?v=3","gravatar_id":"","url":"https://api.github.com/users/chris-armstrong","html_url":"https://github.com/chris-armstrong","followers_url":"https://api.github.com/users/chris-armstrong/followers","following_url":"https://api.github.com/users/chris-armstrong/following{/other_user}","gists_url":"https://api.github.com/users/chris-armstrong/gists{/gist_id}","starred_url":"https://api.github.com/users/chris-armstrong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chris-armstrong/subscriptions","organizations_url":"https://api.github.com/users/chris-armstrong/orgs","repos_url":"https://api.github.com/users/chris-armstrong/repos","events_url":"https://api.github.com/users/chris-armstrong/events{/privacy}","received_events_url":"https://api.github.com/users/chris-armstrong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-30T00:28:08Z","updated_at":"2015-09-30T00:56:56Z","closed_at":null,"body":"## Problem\r\n\r\nWe have a angular SPA that uses ui-router to navigate between different screens in the application. Two of our screens use a ui-gmap-google-map directive. We've noticed that the amount of memory that the application consumes continues to increase if we switch between these two views. We embed our application in a native wrapper using PhoneGap, and it can crash with the increasing memory usage.\r\n\r\n## Investigation \r\nDigging a bit further using Chrome DevTools, it seems that several event listeners remain attached to the DOM when switching states.\r\n\r\nThe next logical step would be to investigate why the Google Maps instances are not being \"destroyed\" between ui-view state changes. The [consensus](http://stackoverflow.com/questions/10485582/what-is-the-proper-way-to-destroy-a-map-instance) seems to be that Google Maps instances (i.e. google.maps.Map) cannot be cleaned up, and that the implicit approach for SPAs is to reuse the Google Map instances.\r\n\r\n## Solutions\r\n\r\nI've put together a quick hack that reuses the google.maps.Map instance from the directive (see [this branch](https://github.com/chris-armstrong/angular-google-maps/tree/2.2.1-map_reuse_hack) ), but it will only work for one Google Map instance on the screen at a time.\r\n\r\nDoes anyone have this issue in their state-based/view-based angular application? This solution could be extended out to maintain a pool of google map instances that are recycled when the scope of the directive is destroyed, reducing the amount of memory leakage from constantly creating Map instances."},"comment":{"url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/comments/144231235","html_url":"https://github.com/angular-ui/angular-google-maps/issues/1538#issuecomment-144231235","issue_url":"https://api.github.com/repos/angular-ui/angular-google-maps/issues/1538","id":144231235,"user":{"login":"nmccready","id":583593,"avatar_url":"https://avatars.githubusercontent.com/u/583593?v=3","gravatar_id":"","url":"https://api.github.com/users/nmccready","html_url":"https://github.com/nmccready","followers_url":"https://api.github.com/users/nmccready/followers","following_url":"https://api.github.com/users/nmccready/following{/other_user}","gists_url":"https://api.github.com/users/nmccready/gists{/gist_id}","starred_url":"https://api.github.com/users/nmccready/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmccready/subscriptions","organizations_url":"https://api.github.com/users/nmccready/orgs","repos_url":"https://api.github.com/users/nmccready/repos","events_url":"https://api.github.com/users/nmccready/events{/privacy}","received_events_url":"https://api.github.com/users/nmccready/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T00:56:56Z","updated_at":"2015-09-30T00:56:56Z","body":"Your resolution looks good to me. I would PR it. Also this would resolve having more than one google maps script in the dom."}}