Skip to content

Memory Leak in Navigation #1215

Closed
Closed
@JimGreenberg

Description

@JimGreenberg

Description of problem:

My team and I are working on an app and we noticed that after a number of navigations the app would ANR and crash under certain conditions. We suspected a memory leak- here is an example of the memory profile during a few repetitions of an action containing a navigation:
screen shot 2018-03-02 at 12 48 36 pm
Note that more memory is freed after each GC.

Here is that same action repeated, but without the navigation:
screen shot 2018-03-02 at 12 46 54 pm
Note that we're able to perform many more actions before the OS decides to GC, indicated by the fineness of the increases in allocated memory- and also that after the GC the memory drops to its starting point whereas the first example this was not the case.

Isolating the issue:

I've created a simple app here: testapp.zip
It consists of 2 pages with a large button that navigates between them. Because the components are so small compared to a production app, this did take some time, however the problem is still visible in the memory profile- memory is unbounded and increasing:
screen shot 2018-03-02 at 1 37 01 pm

What I have tried:

  • Experimented with clearHistory option with navigationExtras
  • Periodically calling the V8 GC explicitly
  • Used the vanilla angular router outlet instead of NS's page router outlet
  • Created a custom reuse strategy (page router outlet does not play nicely at all)
  • Used the vanilla locationstrategy (NSLocationStrategy still spun up however)
  • Refactored to have specific navigation be a child route of another component (This mitigated the issue heavily- enough so that an ANR might never occur under normal use)
    • This of course comes at the cost of defeating all of the features NS put in the page router, so implementing this fullscale seems impractical

Conclusion:

Should components revisited via forward navigation be reinstantiated? This seems like it could be the culprit, however I cannot verify. I'm curious as to whether there are some best practices that I missed, because this seems like such a general issue I'm surprised nobody else has encountered it- everything navigation related that we use is right out of the box. Similar issues posted here are either too old to be relevant (and were already marked as resolved) or related to something else entirely (images in particular).

Thanks for reading

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions