angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Transition with all the data remains in heap - memory leak? #3603

Closed attrobit closed 6 years ago

attrobit commented 6 years ago

This is a (check one box):

My version of UI-Router is: (type version) 1.0.12, but the problem also exists in version 1.0.5

Bug Report

Current Behavior:

When switching between states, the JS-Heap increase and get not garbage collected. See the following screenshot. uirouter-leak1

For the example above i used the uirouter example in plunker.

As i analyzed the heap in detail i saw that the number of Transition-Objects increase with time.

Expected Behavior:

The JS-Heap get garbage collected after switching back to previous state.

Link to Plunker or stackblitz that reproduces the issue:

You can reproduce the problem with the uirouter example app in plunker: example

Just switch multiple times between the state "hello" and "about".

attrobit commented 6 years ago

Similar issue: https://github.com/ui-router/angular/issues/21

christopherthielen commented 6 years ago

Please try your experiment again, but this time click the "collect garbage" button before stopping the profiler (it is the small trash can icon next to the "Memory" checkbox in your screenshot). My tests show that memory use is not increasing significantly.

Applications (and therefore, ui-router) do not have any control over triggering garbage collection. It's done completely at the javascript runtime's discretion.

See this comment for more details on reporting memory leak bugs: https://github.com/angular-ui/ui-router/issues/545#issuecomment-277092153

attrobit commented 6 years ago

Thanks for your reply.

I looked more in Detail by doing a memory heap dump. When i do a heap dump via memory -> take heap snapshot, chrome do a garbage collection before. I did a heap snapshot on hello state, about state and again hello state. The number of memory increase constantly. And i recognized that for every state change a new "Transition"-Object retains in the heap. See the following screenshots.

  1. Hello State: state1

  2. About state: state2

  3. Hello State: state3

christopherthielen commented 6 years ago

for clarity, did you force a garbage collection between each heap dump?

Edit: I tried it myself and see that Transitions are indeed being retained. Thanks for the analysis

christopherthielen commented 6 years ago

This is an issue in uirouter/core. Follow this related issue: https://github.com/ui-router/core/issues/55

attrobit commented 6 years ago

The leak still exist. Testet with Version 1.0.14 (example)

JS-Heap over time (Switched multiple times between hello and about state): uirouter-leak-1014

The number of Transition-Objects still increases. See the foolowing heap-dump. uirouter-leak-heap-1014

christopherthielen commented 6 years ago

reopened https://github.com/ui-router/core/issues/55