React-native: Android Memory Allocations

Created on 22 Nov 2016  路  11Comments  路  Source: facebook/react-native

Description

  • What I did:

    • Created a new React Native project via the CLI

    • Ran the app on a 5x+23 API Emulator via react-native run-android

    • Opened the Android Monitors tab

  • What I expected:

    • I expected the memory allocations to rise at app startup and then plateau.

  • What actually happens:

    • Memory is slowly getting allocated even while the app is just sitting there without any user input.

    • When the memory hits the allocated threshold a garbage collection occurs.

    • Its good the memory can actually get garbage collected meaning there isn't a memory leak.

    • However why is memory always getting allocated??

Reproduction

I have a screen recording uploaded here:
https://youtu.be/F3875gv6tAw

Solution

  • Figure out what is being allocated so often and stop it.
  • Is this related to debug builds only or also release builds?

Additional Information

  • React Native version: 0.37.0
  • Platform: Android (maybe others, untested)
  • Operating System: MacOS
  • Android OS: 23
Stale

Most helpful comment

This is still a thing,
I've created a new project using react-native-create-project with these dependencies:

"react": "16.0.0-alpha.12", "react-native": "^0.47.2"

And it still allocates memory.

image

All 11 comments

Is the emulator actually a good representative of regular memory usage? Can you reproduce this on a real device as well? I think to be sure this is a problem we would want to check release build + real device.

I was able to reproduce it actually on a real device as well. Samsung Galaxy S4 (somewhat lower end testing), and a Nexus 6p (somewhat higher end testing).

From my understanding of memory allocation tracking, device shouldn't matter of the actual trend. Available memory might change but the following should raise a flag:

  • Your app is static, but you see memory being allocated in the monitor.
  • You see spikes of memory allocations in the monitor, but you don鈥檛 think there鈥檚 any app logic to cause this behavior.
  • Excessive garbage collection events slow down the app, so minimize these.
  • If the app runs out of memory, it would causes it to crash.

I think the first bullet point "static app, memory being allocated" is not good and relates to this discussion.

The one thing I haven't checked yet is a release build and can try to do that once we have one available. However I thought the Android Studio Monitors required a debuggable app to hook into.

I've met the same problem, too. The memory is slowly increased.

For a helloworld demo, I got something like this:

adb shell dumpsys meminfo -a com.rnhelloworld

               Pss      Pss   Shared  Private   Shared  Private  Swapped     Heap     Heap     Heap
             Total    Clean    Dirty    Dirty    Clean    Clean    Dirty     Size    Alloc     Free
    TOTAL    53298    10256    16928    37468    27532    10292    12764    48375    35871    12503
    TOTAL    53350    10260    16928    37516    27532    10296    12764    48381    35900    12480
    TOTAL    53446    10260    16928    37612    27532    10296    12764    48383    35776    12606

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

This is still a thing,
I've created a new project using react-native-create-project with these dependencies:

"react": "16.0.0-alpha.12", "react-native": "^0.47.2"

And it still allocates memory.

image

+1 any progress on this?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

So this issue seems to be not relevant enough to be resolved? :( Too bad

I have the same issue in react-native 0.51.0.

I have still getting same issue in react-native 0.51.0

still have same problem in 0.55.2

Was this page helpful?
0 / 5 - 0 ratings