java max heap size,Android的摇篮:什么是javaMaxHeapSize"4克"?

In an android project, build.gradle file, I have been through this line

dexOptions{

javaMaxHeapSize "4g"

}

I would like to know the exact purpose of this javaMaxHeapSize and what does that 4g means. What are other values I can give ?

解决方案

As it mentioned in the answer above, it is just an option to specify the maximum memory allocation pool for a Java Virtual Machine (JVM) for dex operation. And it's the same, as to provide to java the -xmx argument. Due to it's source codes from here, it's setter look like:

if (theJavaMaxHeapSize.matches("\\d+[kKmMgGtT]?")) {

javaMaxHeapSize = theJavaMaxHeapSize

} else {

throw new IllegalArgumentException(

"Invalid max heap size DexOption. See `man java` for valid -Xmx arguments.")

}

So, you can see, that the accepted value should match the \d+[kKmMgGtT]? pattern, and hence not, it even refers to the man java to get to know, how to set the -xmx. You can read the man page here. And it says, that this flag:

Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration.

In your example, 4g is 4 Gigabytes and this is a maximum heap size for dex operation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值