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

Memory Leak on Navigation due to references not being removed from the HashMap #1669

Open
kraigjacobson opened this issue Jul 21, 2021 · 2 comments

Comments

@kraigjacobson
Copy link

Environment

  • CLI: 8.0.2
  • Cross-platform modules:
  • Android Runtime: 8.0.0
  • iOS Runtime (if applicable):
  • Plugin(s):

Describe the bug
When navigating the old fragments are still being referenced in the HashMap so the Garbage Collector doesn't collect them causing a memory leak.

When the navigation's 'clearHistory: true' the backstack is emptied properly but the memory leak remains.
When 'clearHistory: false' you can see all the old pages still in the backstack with different Id names even if they are the same page.

To Reproduce
ns create my-drawer-js --template @nativescript/template-drawer-navigation
Open up the profiler in Android Studio
Go to Memory and start a new profiling session
Navigate to a different page in the template app
Go back to profiler and Dump Java Heap
image

Click the Leaks link
image

Click the FragmentClass
image

Click the Instance
image

Click the References Tab and check the 'Show nearest GC root only' Option
image

The FragmentClass instance can't be released because of the references in the HashMap I believe.

This leak is also caught using leak canary
image

Expected behavior
Fragments should be getting completely removed from memory

Sample project
I used the most vanilla template I could to make sure issues weren't coming from frameworks or plugins
https://www.npmjs.com/package/@nativescript/template-drawer-navigation

Additional context

@farfromrefug
Copy link
Contributor

@kraigjacobson did you try to force a callof GC? Maybe the the gc was not triggered yet

@triniwiz
Copy link
Member

@kraigjacobson can you try this on the latest runtime and latest core version, I believe this was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants