Android java.lang.OutOfMemoryError: GC overhead limit exceeded

​ 再用 Android Studio 编辑项目的时候,会出现如下错误。

1
java.lang.OutOfMemoryError: GC overhead limit exceeded

​ 根据 Sun 的描述:

1
"if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown."

​ 首先更改 Android Studio 的运行内存,MacBook 在Content/bin/studio.vmoptions,修改如下

1
2
3
4
5
6
7
8
9
10
11
#
# *DO NOT* modify this file directly. If there is a value that you would like to override,
# please add it to your user specific configuration file.
#
# See http://tools.android.com/tech-docs/configuration
#
-Xms256m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=768m
-XX:+UseCompressedOops

​ 之后在项目的build.gradle中添加一个设置:

1
2
3
exOptions {
javaMaxHeapSize "4g"
}

​ 接下来运行就能通过。

Comments

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×