NativeScript / NativeScript/ios

Memory Leak on Page Navigation on NS7

Open
#107 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
150
Forks
43
Avg merge
3d 10h
Merged PRs (30d)
22

Description

Environment

"@nativescript/core": "7.3.0"

"nativescript-vue": "^2.8.1"

"@nativescript/ios": "7.2.0"

✔ Component nativescript has 7.2.1 version and is up to date.

✔ Component @nativescript/core has 7.3.0 version and is up to date.

✔ Component @nativescript/ios has 7.2.0 version and is up to date.

Describe the bug

NS is not freeing memory on page navigations on iOS. When profiling, on each page navigation, the memory increases and app gets slower until, at some point, the app freezes or the OS terminates the app. This behaviour is restricted to IOS, we have profiled with the Android Runtime (https://github.com/NativeScript/android-runtime) and the garbage collection works as expected.

On a very simple application, two included below, each page navigation increases the memory footprint of the app by 60 - 80 megs until the app reaches 1 - 2 Gigs and stops working. If we have a complex page, with some images, and scroll on a list then the memory increases in small iterations but once we navigate to a new page, the memory jumps by 60 - 80 megs.

We have created several test apps with Vue and Angular and the memory leak occurs irrespective of the JS framework.

Solutions Tried and Reviewed
  1. The same issues has been posted previously - Memory Leak on 7.2.0 with (https://github.com/NativeScript/ns-v8ios-runtime)
    https://github.com/NativeScript/ns-v8ios-runtime/issues/105

    We have also:

    EnableProdMode: Is there something similar to enable prod mode on Vue
    https://github.com/NativeScript/nativescript-angular/issues/1215
    Markingmode: https://nativescript.org/blog/markingmode-none-is-official-boost-android-performance-while-avoiding-memory-issues/

  2. Downgraded Nativescript iOSCore to 6.5.4 (https://github.com/NativeScript/ios-runtime).

    We experience the same issues with the older runtime.

  3. Manually destroyed the component - tried different call backs (Unloaded for example)
    https://github.com/nstudio/nativescript-videoplayer/issues/129

  4. Tried with Angular (its happening even on the creation project templates)

  5. Tried with the templates project with 6.5.4

  6. Set the V8flags in the config for IOS (on the V8 Runtime https://github.com/NativeScript/ns-v8ios-runtime)

  7. Navigating with the clearHistory flag (set to true) and navigateBack method = same result

  8. Tested on simulators and real iPhones. (iOS 12.4.8, iOS 13.1, 13.3.1)

  9. Tested with different Layouts (complex and simple)

  10. Manually calling the GC in the navigate back method reduces the memory by a small percentage (0.1% - 0.3%).

  11. As mentioned, it works on Android, see the profiling from below.
    android memory metrics

Project Examples

We include two sample projects, the first is NS7 and the second NS6, both exhibit the same issues with memory.

NS7: https://github.com/alkimiiapps/memoryleakexample

NS6: https://github.com/alkimiiapps/ns6test

Example Video of the memory reaching 0.5 Gig

Here is a gif of the profiling, where the user navigates back and forth between pages and the memory increases with each navigation.

IMAGE ALT TEXT HERE

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the leak with the linked NS7 and NS6 sample projects, then profile repeated page navigation on iOS and compare the behavior with Android. The issue is complete when the source of the retained memory is identified and navigation no longer causes the reported memory growth or eventual freeze.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.