Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 3 tasks
attrobit opened this issue Jan 11, 2018 · 7 comments
Closed
1 of 3 tasks

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

attrobit opened this issue Jan 11, 2018 · 7 comments
Labels

Comments

@attrobit
Copy link

This is a (check one box):

  • Bug Report
  • Feature Request
  • General Query

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
Copy link
Author

attrobit commented Jan 11, 2018

Similar issue: ui-router/angular#21

@attrobit attrobit reopened this Jan 11, 2018
@christopherthielen
Copy link
Contributor

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: #545 (comment)

@attrobit
Copy link
Author

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
Copy link
Contributor

christopherthielen commented Jan 14, 2018

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
Copy link
Contributor

This is an issue in uirouter/core. Follow this related issue: ui-router/core#55

@attrobit
Copy link
Author

attrobit commented Feb 2, 2018

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
Copy link
Contributor

reopened ui-router/core#55

wawyed pushed a commit to wawyed/core that referenced this issue Mar 3, 2018
The treeChanges object has references to the PathNodes from the previous transition (`.treeChanges("from")`).
The PathNode object has resolve data inside it.
The previous transition is reachable via a resolve (via tokens: `"$transition$"` or `Transition`).
Through this chain, all other transitions are reachable and not eligible for GC.

This change cleans out the previous Transition object from the resolves, but only
after a transition has been evicted from the `successfulTransitions` queue.
The `successfulTransitions` queue currently has a max size of 1, so the transition
is cleaned up once it is no longer the current nor previous transition
(it is cleaned when it's the previous previous transition);

Fixes ui-router#55
Fixes angular-ui/ui-router#3603
Fixes ui-router/angular#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants