your programing

오류 java.lang.OutOfMemoryError : GC 오버 헤드 제한 초과

lovepro 2020. 9. 29. 08:16
반응형

오류 java.lang.OutOfMemoryError : GC 오버 헤드 제한 초과


JUnit 테스트를 실행할 때이 오류 메시지가 표시됩니다.

java.lang.OutOfMemoryError: GC overhead limit exceeded

이 무엇인지 알고 OutOfMemoryError있지만 GC 오버 헤드 제한은 무엇을 의미합니까? 어떻게 해결할 수 있습니까?


이 메시지는 어떤 이유로 가비지 수집기가 과도한 시간 (기본적으로 프로세스의 모든 CPU 시간의 98 %)을 많이 사용하고 각 실행에서 매우 적은 메모리 (기본적으로 힙의 2 %)를 복구 함을 의미합니다.

이것은 효과적으로 프로그램이 진행을 중지하고 항상 가비지 콜렉션 만 실행 중임을 의미합니다.

애플리케이션이 아무 작업도 수행하지 않고 CPU 시간을 흡수하지 못하도록하기 위해 JVM Error은 문제를 진단 할 수 있도록이를 처리합니다.

내가 본 드문 경우는 일부 코드가 이미 메모리가 제한된 환경에서 수많은 임시 객체와 약하게 참조 된 객체를 생성하는 경우입니다.

자세한 내용이 기사 (특히이 부분 ) 확인하십시오 .


GC는 너무 많은 시간을 가비지 수집에 소비하여 너무 적은 반환을 할 때이 예외를 발생시킵니다. CPU 시간의 98 %가 GC에 사용되고 2 % 미만의 힙이 복구됩니다.

이 기능은 힙이 너무 작아서 진행률이 거의 또는 전혀없는 상태에서 응용 프로그램이 장시간 실행되는 것을 방지하도록 설계되었습니다.

명령 줄 옵션으로이 기능을 끌 수 있습니다. -XX:-UseGCOverheadLimit

여기에 더 많은 정보

편집 : 누군가 나보다 빨리 입력 할 수있는 것 같습니다. :)


프로그램에 메모리 누수 가 없다고 확신하는 경우 다음을 시도하십시오.

  1. 예를 들어 힙 크기를 늘리십시오 -Xmx1g.
  2. 동시 낮은 일시 중지 수집기를 활성화합니다 -XX:+UseConcMarkSweepGC.
  3. 가능한 경우 기존 개체를 재사용하여 메모리를 절약하십시오.

필요한 경우 명령 줄에 옵션 추가 하여 제한 검사 를 비활성화 할 수 있습니다 -XX:-UseGCOverheadLimit.


일반적으로 코드입니다. 다음은 간단한 예입니다.

import java.util.*;

public class GarbageCollector {

    public static void main(String... args) {

        System.out.printf("Testing...%n");
        List<Double> list = new ArrayList<Double>();
        for (int outer = 0; outer < 10000; outer++) {

            // list = new ArrayList<Double>(10000); // BAD
            // list = new ArrayList<Double>(); // WORSE
            list.clear(); // BETTER

            for (int inner = 0; inner < 10000; inner++) {
                list.add(Math.random());
            }

            if (outer % 1000 == 0) {
                System.out.printf("Outer loop at %d%n", outer);
            }

        }
        System.out.printf("Done.%n");
    }
}

java 1.6.0_24-b07 사용 Windows7 32 비트에서.

java -Xloggc : gc.log GarbageCollector

그런 다음 gc.log를보십시오.

  • BAD 메서드를 사용하여 444 회 트리거 됨
  • WORSE 방법을 사용하여 666 번 트리거 됨
  • BETTER 방법을 사용하여 354 번 트리거 됨

Now granted, this is not the best test or the best design but when faced with a situation where you have no choice but implementing such a loop or when dealing with existing code that behaves badly, choosing to reuse objects instead of creating new ones can reduce the number of times the garbage collector gets in the way...


Cause for the error

GC overhead limit exceeded" indicates that the garbage collector is running all the time and Java program is making very slow progress.

After a garbage collection, if the Java process is spending more than approximately 98% of its time doing garbage collection and if it is recovering less than 2% of the heap and has been doing so far the last 5 (compile time constant) consecutive garbage collections, then a java.lang.OutOfMemoryError is thrown

  1. Increase the heap size if current heap is not enough.
  2. If you still get this error after increasing heap memory, use memory profiling tools like MAT ( Memory analyzer tool), Visual VM etc and fix memory leaks.
  3. Upgrade JDK version to latest version ( 1.8.x) or at least 1.7.x and use G1GC algorithm. . The throughput goal for the G1 GC is 90 percent application time and 10 percent garbage collection time
  4. Apart from setting heap memory with -Xms1g -Xmx2g , try

    -XX:+UseG1GC -XX:G1HeapRegionSize=n -XX:MaxGCPauseMillis=m  
    -XX:ParallelGCThreads=n -XX:ConcGCThreads=n
    

Have a look at some more related questions regarding G1GC

Java 7 (JDK 7) garbage collection and documentation on G1

Java G1 garbage collection in production

Oracle technetwork article for GC finetuning


Just increase the heap size a little by setting this option in

Run → Run Configurations → Arguments → VM arguments

-Xms1024M -Xmx2048M

Xms - for minimum limit

Xmx - for maximum limit


For me, the following steps worked:

  1. Open the eclipse.ini file
  2. Change

    -Xms40m
    -Xmx512m
    

    to

    -Xms512m
    -Xmx1024m
    
  3. Restart Eclipse

See here


try this

open the build.gradle file

  android {
        dexOptions {
           javaMaxHeapSize = "4g"
        }
   }

The following worked for me. Just add the following snippet:

android {
        compileSdkVersion 25
        buildToolsVersion '25.0.1'

defaultConfig {
        applicationId "yourpackage"
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
dexOptions {
        javaMaxHeapSize "4g"
    }
}

increase javaMaxHeapsize in your build.gradle(Module:app) file

dexOptions {
    javaMaxHeapSize "1g"
}

to (Add this line in gradle)

 dexOptions {
        javaMaxHeapSize "4g"
    }

Rebooting my MacBook fixed this issue for me.


You can also increase memory allocation and heap size by adding this to your gradle.properties file:

org.gradle.jvmargs=-Xmx2048M -XX\:MaxHeapSize\=32g

It doesn't have to be 2048M and 32g, make it as big as you want.


You need to increase the memory size in Jdeveloper go to setDomainEnv.cmd.

set WLS_HOME=%WL_HOME%\server    
set XMS_SUN_64BIT=**256**
set XMS_SUN_32BIT=**256**
set XMX_SUN_64BIT=**3072**
set XMX_SUN_32BIT=**3072**
set XMS_JROCKIT_64BIT=**256**
set XMS_JROCKIT_32BIT=**256**
set XMX_JROCKIT_64BIT=**1024**
set XMX_JROCKIT_32BIT=**1024**

if "%JAVA_VENDOR%"=="Sun" (
    set WLS_MEM_ARGS_64BIT=**-Xms256m -Xmx512m**
    set WLS_MEM_ARGS_32BIT=**-Xms256m -Xmx512m**
) else (
    set WLS_MEM_ARGS_64BIT=**-Xms512m -Xmx512m**
    set WLS_MEM_ARGS_32BIT=**-Xms512m -Xmx512m**
)

and

set MEM_PERM_SIZE_64BIT=-XX:PermSize=**256m**
set MEM_PERM_SIZE_32BIT=-XX:PermSize=**256m**

if "%JAVA_USE_64BIT%"=="true" (
    set MEM_PERM_SIZE=%MEM_PERM_SIZE_64BIT%
) else (
    set MEM_PERM_SIZE=%MEM_PERM_SIZE_32BIT%
)

set MEM_MAX_PERM_SIZE_64BIT=-XX:MaxPermSize=**1024m**
set MEM_MAX_PERM_SIZE_32BIT=-XX:MaxPermSize=**1024m**

I'm working in Android Studio and encountered this error when trying to generate a signed APK for release. I was able to build and test a debug APK with no problem, but as soon as I wanted to build a release APK, the build process would run for minutes on end and then finally terminate with the "Error java.lang.OutOfMemoryError: GC overhead limit exceeded". I increased the heap sizes for both the VM and the Android DEX compiler, but the problem persisted. Finally, after many hours and mugs of coffee it turned out that the problem was in my app-level 'build.gradle' file - I had the 'minifyEnabled' parameter for the release build type set to 'false', consequently running Proguard stuffs on code that hasn't been through the code-shrinking' process (see https://developer.android.com/studio/build/shrink-code.html). I changed the 'minifyEnabled' parameter to 'true' and the release build executed like a dream :)

In short, I had to change my app-level 'build.gradle' file from: //...

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.sign_config_release
    }
    debug {
        debuggable true
        signingConfig signingConfigs.sign_config_debug
    }
}

//...

to

    //...

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.sign_config_release
    }
    debug {
        debuggable true
        signingConfig signingConfigs.sign_config_debug
    }
}

//...

To increase heap size in IntelliJ IDEA follow the following instructions. It worked for me.

For Windows Users,

Go to the location where IDE is installed and search for following.

idea64.exe.vmoptions

Edit the file and add the following.

-Xms512m
-Xmx2024m
-XX:MaxPermSize=700m
-XX:ReservedCodeCacheSize=480m

That is it !!


Solved:
Just add
org.gradle.jvmargs=-Xmx1024m
in
gradle.properties
and if it does not exist, create it.


In Netbeans, it may be helpful to design a max heap size. Go to Run => Set Project Configuration => Customise. In the Run of its popped up window, go to VM Option, fill in -Xms2048m -Xmx2048m. It could solve heap size problem.

참고URL : https://stackoverflow.com/questions/1393486/error-java-lang-outofmemoryerror-gc-overhead-limit-exceeded

반응형