Skip to content
Sandny Blog
  • Home
  • Java
  • JavaScript
  • AWS
  • Embedded
  • About
react-native heap limit allocation android

Android/iOS React-native heap limit allocation failed error

  • December 30, 2019January 8, 2020
  • by Coder Kai

When you are building your react native Android app, you may encounter the error: heap limit Allocation failed.

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Usually, this error occurs when your app is using many libraries and when it’s become larger.

As the error describes, its a heap error where it is not enough to perform the tasks. React-native runs a node service to bundle the libraries. When your library count is larger, the node service will require more memory and at a point, it will throw the above error.

Solution for react-native heap limit allocation failed error

Obviously, if you are not going to cut down your libraries, you will have to increase the heap memory allocation. For this memory-hungry operation, we don’t have an optimized solution. In fact, even if it is efficient in memory, it will take more time than it already is when building the bundles.
So the best option will be to increase the memory size

How to increase the heap memory size?

You can use the following path parameter to increase the heap memory

max_old_space_size

By invoking the node service manually with the following command we can allow the service to use 8192Mb (8Gb) memory for the node service.

node --max-old-space-size=8192 node_modules/react-native/local-cli/cli.js start

You can use the desired memory which suites your machine which won’t be starving other programmes in case of exponential heap overflow.

Bundled Releases

For any bundled releases which you use to build .aab or .apk bundles, you can define the values in app/bundle.gradle file

project.ext.react = [
    // keep the entry file and hermes params
    nodeExecutableAndArgs: ["node", "--max-old-space-size=8192"]
]

This will provide the build script with the path parameters for the node service.

ios

You can enter the values in the Bundle React Native code and imagessection under the Build Phases

export NODE_BINARY=node 
export NODE_ARGS=--max-old-space-size=8192
export NODE_OPTIONS=--max-old-space-size=8192
../node_modules/react-native/scripts/react-native-xcode.sh
react-native heap limit allocation failed error

Finally, always keep an eye on memory usage. React native use memory majorly for the node service and JVM for android builds. Xcode also uses a significant amount of memory. So take special note if you are running your emulators also when building.

Checkout following blog to setup FCM Push Notification with React Native apps.

How to setup FCM Push Notification with React Native App
JDK 14 – The new features in Java 14
How to avoid NullPointerException in Java
Coder Kai
A humble developer
android heap heap limit allocation failed ios memory node react-native

Related articles

Minimum supported Gradle Version
Minimum supported Gradle version is…
debounce with react hooks
Avoid multiple clicks using debounce…
androidx fileprovider
AndroidX ClassNotFound Exception: “android.support. v4.content…
FCM Push Notification with React Native
How to setup FCM Push…

Categories

  • android 3
  • Apollo Client 1
  • AWS 8
    • AppSync 5
    • EC2 1
    • EKS 1
    • Route53 1
    • S3 1
  • AWS Amplify 1
  • Chakra UI 1
  • Docker 1
  • Embedded 1
  • EmberJS 1
  • FCM 1
  • Godaddy 1
  • GraphQL 3
  • ios 1
  • Jasper 1
  • Java 10
    • Java 11 1
    • Java 14 1
  • JavaEE 2
  • JavaScript 39
    • Express.js 4
    • Javascript Guide 7
    • Node.js 3
    • react-native 4
    • React.js 17
    • Typescript 1
  • Kubernetes 1
  • machine learning 1
  • Maven 2
  • OCaml 3
  • PostgreSQL 1
  • Python 2
  • react-native 4
  • ReactJS 3
  • sass 1
  • Server 6
  • spark 1
  • Terraform 2
  • Ubuntu 4
  • Uncategorized 1
  • webpack 2

Recent Comments

  • binance register on Chakra UI Animations
  • binance account on SSL Websocket proxy with Nginx for Graphql Subscriptions
  • Binance Pag-signup on How to fetch data with useEffect

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • October 2022 3
  • September 2022 7
  • May 2022 1
  • December 2021 1
  • August 2021 1
  • July 2021 6
  • June 2021 3
  • February 2021 1
  • July 2020 1
  • December 2019 5
  • November 2019 6
  • October 2019 3
  • August 2019 1
  • March 2019 1
  • February 2019 1
  • January 2019 2
  • December 2018 1
  • September 2018 2
  • August 2018 1
  • June 2018 1
  • February 2018 1
  • November 2017 2
  • October 2017 5
  • September 2017 1
  • June 2017 1
  • May 2017 10
Sandny Blog space
Theme by Colorlib Powered by WordPress