Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of memory Application crash React Native

Using React Native 0.33 After some seconds, the application stops (only tested on Android)

Looking at the android logs I get :

enter image description here

I have no idea how to examine the problem.

like image 307
gpasse Avatar asked Sep 23 '16 08:09

gpasse


People also ask

How memory management is done in React Native?

In JavaScript memory is managed automatically by Garbage Collector (GC). In short, Garbage Collector is a background process that periodically traverses the graph of allocated objects and their references.

How do I test the performance of React Native app?

To measure performance, it's advised by the React Native devs to disable the JS Dev mode. To do so, open the development menu, and go to settings. Otherwise, you might spot issues that won't be existing in the released version of your app.

What is React Native Flipper?

What is Flipper? Flipper is a highly extensible mobile app debugger used to debug iOS, Android and React Native applications. It lets you inspect, control, and visualize your application from its desktop application.


2 Answers

this fixes my issue:

Add this to your "android/app/src/main/AndroidManifest.xml"

<application android:largeHeap="true"

ref: https://github.com/facebook/react-native/issues/6799

like image 129
TeYoU Avatar answered Oct 21 '22 03:10

TeYoU


Using the below might help you

    <application android:largeHeap="true">

But you might need to check your application for possible memory leaks. for eg:

  1. Unreleased timers/listeners added in componentDidMount
  2. Closure scope leaks.
  3. Large image sizes.
  4. Use of global variables.

We were facing the same issues with our react native app. It took us a lot of time and effort in making our apps somewhat stable. You can check out this blog which helped us a lot https://blog.swmansion.com/hunting-js-memory-leaks-in-react-native-apps-bd73807d0fde

Update: Loading large amount of data in API continuously was putting load on the RAM at least on low end devices causing Out of Memory issues. You will need to clean this up as well and find a better and optimised way to load data.

like image 35
Aniket Rane Avatar answered Oct 21 '22 05:10

Aniket Rane