当我执行JUnit测试时,我得到了这个错误消息:

java.lang.OutOfMemoryError: GC overhead limit exceeded

我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?


当前回答

我不知道这是否仍然相关,但只是想分享对我有用的东西。

更新kotlin版本至最新可用版本。https://blog.jetbrains.com/kotlin/category/releases/

做完了。

其他回答

要在IntelliJ IDEA中增加堆大小,请遵循以下说明。这对我很管用。

对于Windows用户,

转到安装IDE的位置并搜索以下内容。

idea64.exe.vmoptions

编辑该文件并添加以下内容。

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

就是这样!!

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 :)

简而言之,我必须改变应用程序级别的“构建”。Gradle文件来自: / /……

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
    }
}

//...

@Buhb 我在一个普通的spring-boot web应用程序的main方法中复制了这个过程。代码如下:

public static void main(String[] args) {
    SpringApplication.run(DemoServiceBApplication.class, args);
    LOGGER.info("hello.");
    int len = 0, oldlen=0;
    Object[] a = new Object[0];
    try {
        for (; ; ) {
            ++len;
            Object[] temp = new Object[oldlen = len];
            temp[0] = a;
            a = temp;
        }
    } catch (Throwable e) {
        LOGGER.info("error: {}", e.toString());
    }
}

引起come的示例代码也是来自oracle java8语言规范。

我在使用Oracle web逻辑服务器时得到了这个错误。我分享我的答案作为参考,以防有人最终在这里寻找解决方案。

所以,如果你试图提升Oracle web逻辑服务器并得到这个错误,那么你只需要增加运行服务器的初始和最大堆大小。

转到- > C:\Oracle\Middleware\Oracle_Home\user_projects\domains\wl_server\bin 打开setDomainEnv.cmd 检查设置USER_MEM_ARGS值,如果小于 set USER_MEM_ARGS="- xms128m - Xmx8192m ${MEM_DEV_ARGS} ${MEM_MAX_PERM_SIZE}"

这意味着初始堆大小设置为128 MB,最大堆大小为8GB。 现在,只需保存文件并重新启动服务器。如果不能解决问题,请尝试增加大小或寻找优化服务的方法。

参考,检查这个链接:https://docs.oracle.com/cd/E49933_01/server.770/es_install/src/tins_postinstall_jvm_heap.html

edit:检查您是否能够在运行服务器时看到更新的java参数。就像这样 如果它像以前一样,那么替换setDoaminEnv中显示的值。CMD由简单的搜索和替换。

Java堆大小描述(xms, xmx, xmn)

-Xms size in bytes

Example : java -Xms32m

设置Java堆的初始大小。 默认大小为2097152 (2MB)。 该值必须是1024字节(1KB)的倍数且大于1024字节。 (-server标志将默认大小增加到32M。)

-Xmn size in bytes

Example : java -Xmx2m

设置Eden生成的初始Java堆大小。 默认值为640K。 (-server标志将默认大小增加到2M。)

-Xmx size in bytes

Example : java -Xmx2048m

设置Java堆可以增长到的最大大小。 默认大小为64M。 (-server标志将默认大小增加到128M。) 最大堆限制大约是2 GB (2048MB)。

Java内存参数(xms, xmx, xmn)格式化

在设置Java堆大小时,应该使用字母“m”或“m”表示MB,或使用字母“g”或“g”表示GB来指定内存参数。如果指定“MB”或“GB”,则该设置将不起作用。有效参数是这样的:

-Xms64m或-Xms64m -Xmx1g或-Xmx1g 还可以用2048MB指定2GB吗 另外,确保在指定参数时使用整数。使用-Xmx512m是一个有效的选项,但是-Xmx0.5g会导致错误。

这种推荐对某些人是有帮助的。