且构网

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

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

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

我想说你的构建内存不足,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.