Java.lang.OutOfMemoryError : unable to create new native thread error

Java.lang.OutOfMemoryError : unable to create new native thread error … here is a solution to the problem.

Java.lang.OutOfMemoryError : unable to create new native thread error

Recently updated to Android 2.2.

Try to open an existing project. It prompted me to convert, and I accepted. The project was imported successfully, but whenever I try to build, I get:

Error:Execution failed for task ':app:mergeDebugResources'. > java.lang.OutOfMemoryError: unable to create new native thread

I’ve added:

org.gradle.daemon=false
GRADLE_OPTS="-Xmx2048m -Xms2048m -XX:MaxPermSize=1024m"
org.gradle.jvmargs=-XX:MaxPermSize=512m

to gradle.properties. Still, it didn’t work.

Solution

Whenever the JVM requests a new thread from the operating system, you have a chance to encounter java.lang.OutOfMemoryError: Unable to create new native thread 。 This OutOfMemoryError is thrown whenever the underlying operating system is unable to allocate a new native thread. The exact limits of native threads are very platform-dependent, so we recommend finding out these limits by running tests similar to the following examples. However, in general, the situation that causes java.lang.OutOfMemoryError: Unable to create a new native thread goes through the following stages:

  1. An application running internally requests a new Java thread
    Virtual machines
  2. The JVM native code proxies a request to create a new native
    The operating system tries to create a new native thread
    Memory needs to be allocated for the thread
  3. The operating system refuses
    native memory allocation is either because of the 32-bit Java process size
    It has exhausted its memory address space – e.g. (2-4) GB process size
    The limit has been reached – or the operating system’s virtual memory is full
    Depleted
  4. java.lang.OutOfMemoryError: Unable to create a new native
    A threading error is thrown.

Quote: https://plumbr.eu/outofmemoryerror/unable-to-create-new-native-thread

Related Problems and Solutions