Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

Memory leaks when developer tools are open in Chrome #1524

Open
brgrz opened this issue Sep 21, 2015 · 26 comments
Open

Memory leaks when developer tools are open in Chrome #1524

brgrz opened this issue Sep 21, 2015 · 26 comments
Labels
Milestone

Comments

@brgrz
Copy link

brgrz commented Sep 21, 2015

I finally nailed this down. AGM's memory consumption skyrockets when Chrome dev tools are opened. It'd go from 200 MB to 600 MB instantly and then after a few pans/zooms it would go to 800-1GB.

User experience quickly becomes a pain, UI starts freezing/hanging.

I have tested this with 2.1.6 and 2.2.1 with the Example project from source. The same happens when using the demo online.

What could this relate to? Some debug settings in AGM code?

@nmccready nmccready added this to the 2.2.2 milestone Sep 21, 2015
@nmccready
Copy link
Contributor

I am not seeing this; I do see some memory not being collected but nothing as extreme as you state. I need more steps to reproduce. Help me help you.

@nmccready
Copy link
Contributor

I did several zoom in/outs and pans and generated 1000 clusters and non cluster markers. Memory never got over 430 MB. It did collect later on back down to 406MB.

@brgrz
Copy link
Author

brgrz commented Sep 21, 2015

I too can't reproduce it right now when I'm in a different user profile on my dev machine but I did notice it a lot before. Strange. Will continue to monitor the behavior.

@spyridonas
Copy link

Since you reference my issue I can only provide the following info : my memory goes through the roof because when I update the markers the old ones don't get destroyed. So my scope has 3 event handlers, then 6, then 9, 12 etc. Imagine that increase every half second and you got problem. Can you create a clearAll(); ? Thanks.

@nmccready
Copy link
Contributor

There is already a Plurals.clear via control. Which MarkersParent inherits. Also you guys really havent stated exactly which directive is your problem. I assume it is ui-gmap-markers but it could be ui-gmap-marker,

https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/plural.coffee#L14-L15

@nmccready
Copy link
Contributor

It does seem AngularJS Batarang is more stable then it has been in a while. I do see that some scopes are not cleaning up.

@nmccready
Copy link
Contributor

To me looking at the scopes that are around it appears to be windows, or window lingering.

@spyridonas
Copy link

Thanks, i do use ui-gmap-markers. I don't know if brgrz has the same problem , maybe he can try and implement the Plurals.clear ?I will try to. About the windows, yes i do have infoWindows on all of my markers. (video showing the issue https://vid.me/7Mhp)

@nmccready
Copy link
Contributor

To me markers does not appear to be a problem but if your using windows with it then you may have an issue.

@nmccready
Copy link
Contributor

I am coming to these assumptions by looking at example.js/.html , all the leaky scopes have either show, isIconVisibleOnClick, or template which are all window stuff.

@nmccready
Copy link
Contributor

I found and fixed one of the leaks.

nmccready added a commit to nmccready/angular-google-maps that referenced this issue Sep 22, 2015
- WindowsParent model now correctly destroys its child model's scopes.
- coffeelint fixes
- templates in child windows will destroy when its window scope destroys

issue angular-ui#1524
@nmccready
Copy link
Contributor

Commit above has fixes; I will PR it later.

@spyridonas
Copy link

Thank you for taking the time to look at the issue, using your commit i did see a noticeable improvement. There are still more leaks though and it's still on the windows and i think there is another one someone else

@spyridonas
Copy link

After trying to find the issue a possible finding is that the window html cache doesn't get removed. Some answers from stackoverflow "The entries in the cache object do only get removed if jQuery knows that the elements have been removed. That is the elements have to be removed with jQuery." and "I changed the plugin code to unbind the event handlers and remove the data in the plugin's destroy() method, that eventually removed the memory leak."

@nmccready
Copy link
Contributor

As for the cache issues I recommend replacing angulars cache with this https://github.com/jmdobry/angular-cache , it automatically does an LRU cache based on your config.

@nmccready
Copy link
Contributor

Closing w/PR #1528

@spyridonas
Copy link

When using the angular-cache you stated above the html cache of infoWindow still remains between refreshes ( I don't do any caching, i mean the cache you have inside your plugin). Also note that watchers are going up all the time.

@nmccready
Copy link
Contributor

Ok, mis interpreted what you said. So you mean the templated window is stuck in scope. Yeah I did see that and I tried to fix it but got nowhere. So I don't have a fix for that at the moment. Make a new ticket for that. Be nice if someone else dived into this.

@nmccready
Copy link
Contributor

@spyridonas I'll reopen this but you need to be clear on what code lines help you. Just rambling will get you no where. Please learn git conventions via markdown for copying code lines and using code blocks.

markdown cheat sheat

@nmccready nmccready reopened this Sep 24, 2015
@nmccready
Copy link
Contributor

Also what is leaking / remaining besides the template stuff.
Just stating:

Can somebody implement this fix properly and pr it ?

Is a sure way to get no one to help you. Because basically it means this:

13bbe1a8d29dbe9d82ff769f6561c66a285a64ed30630445c138a664983a91d4

@spyridonas
Copy link

Ok i will try my best, here are my modifications

https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/models/child/window-child-model.coffee#L200 (method destroy)

destroy: (manualOverride = false) =>
          @remove()
          if (@scope? and not @scope?.$$destroyed) and (@needToManualDestroy or manualOverride)
            @scope.$destroy()
          @hideWindow()
          @removeEvents @listeners
          @listeners.length = 0
          delete @gObject
          delete @opts

https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/managers/marker-manager.coffee#L56 (method destroy)

destroy: (manualOverride = false) =>
          @remove()
          if (@scope? and not @scope?.$$destroyed) and (@needToManualDestroy or manualOverride)
            @scope.$destroy()
          @hideWindow()
          @removeEvents @listeners
          @listeners.length = 0
          delete @gObject
          delete @opts
          @clear

https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/managers/marker-manager.coffee#L59 (method clear)

    clear: =>
      @gMarkers.each (gMarker) ->
        gMarker.setMap null
      delete @gMarkers
      @hideWindow()
      @removeEvents @listeners
      @listeners.length = 0
      delete @gObject
      delete @gMarkers
      delete @opts
      @gMarkers = new PropMap()

Apart from the obvious errors in the console, most leaks are fixed that way.
That's the code that needs cleanup and pr. Also adding the @listeners on the marker-manager.coffee (i don't know how to do that) so they get destroyed as well

@nmccready
Copy link
Contributor

You know github has line highlighting built into the urls if you click a line.

https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/models/child/window-child-model.coffee#L200

Notice #L200 .

Also when you go to the root page of any github project if you hit the keyboard 'T' key it will open up a fast search for files in a project. Example hit T then type window-ch and window-child-model is right there.

@nmccready
Copy link
Contributor

A child should not be touching the manager from the clean perspective. But I thought you stated that you made progress copying and pasting something.. what did you try? Whats lines of js did u move?

@spyridonas
Copy link

Exactly, i copy-pasted all the lines from https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/models/child/window-child-model.coffee#L193 and i think all of my leaks are fixed. At the bare minimum if the "remove" has the same lines as "destroy" you can already see an improvement (in the same file).

@nmccready
Copy link
Contributor

yeah but where did you paste it too? Thinking the leak is fixed is not enough. More then likely many times you break something somewhere else.

@spyridonas
Copy link

@nmccready nmccready modified the milestones: 2.2.2, 2.3.1 Jan 25, 2016
@nmccready nmccready modified the milestones: 2.3.1, 2.3.2 Feb 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants