且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Studio将hprof文件转储到项目文件夹中

更新时间:2023-01-11 18:36:48

我会说您的构建内存不足,并且Gradle默认情况下已设置-XX:+HeapDumpOnOutOfMemoryError,因此如果内存不足,您将获得堆转储.我想知道您是否也没有显示OOM.

I'd say your build went out of memory and Gradle has by default -XX:+HeapDumpOnOutOfMemoryError set, so you get a heap dump in case of out of memory. I wonder that you don't also get the OOM displayed though.

您应该尝试增加授予构建的最大内存.添加e. g.

You should try to increase the max memory that you grant to your build. Add e. g.

org.gradle.jvmargs = -Xmx2g -XX:+HeapDumpOnOutOfMemoryError

添加到项目gradle.properties文件(如果不存在,请创建该文件,它必须位于根项目目录中)以增加最大内存.

to your projects gradle.properties file (create it if not present, it has to be in the root projects directory) to increase the max memory.

当然也可能是您的构建脚本中存在内存泄漏,因此在运行过程中会累积内存.如果使用gradlew --stop杀死gradle守护程序,然后仅在进行几次构建后此行为才恢复,则可能存在内存泄漏,应调查并修复.如果在停止守护程序后立即失败,则您的构建可能仅需要更多内存.如果问题是内存泄漏,那么在比以前更多的构建之后,增加最大内存只会暂时有用,并且您将获得相同的行为.

It could of course also be that you have a memory leak in your build scripts, so that the memory cumulates over runs. If you kill the gradle daemon with gradlew --stop and then this behavior comes back only after a few builds, then you probably have a memory leak that you should investigate and fix. If it fails immediately after stopping the daemon, your build might simply need more memory. If the problem is a memory leak, increasing the max memory will only help temporarily and you will get the same behavior, just after more builds than before.