简体   繁体   English

如何在Android中增加堆大小?

[英]How to increase heap size in Android?

So my question is similar to this: Android: how to increase heap size at runtime? 所以我的问题类似于: Android:如何在运行时增加堆大小?

However, since I'm not dealing with caching, the answer provided about a better caching implementation does not apply to me. 但是,由于我不处理缓存,因此提供的关于更好的缓存实现的答案不适用于我。 My goal is allocate a large heap as a temporary solution to my timing issue that I believe GC_CONCURRENT is affecting and my goal is to allocate a heap such that GC_CONCURRENT doesn't happen. 我的目标是分配一个大堆作为我认为GC_CONCURRENT正在影响的计时问题的临时解决方案,而我的目标是分配一个堆,以使GC_CONCURRENT不会发生。 I would like to emphasize I do not have a memory leak as when GC_CONCURRENT runs it always frees up 15% and that number does not go down and I've since optimized my code such that I have no variable initializations in any loops and things are declared static and final where possible. 我想强调一点,我没有内存泄漏,因为当GC_CONCURRENT运行时,它总是释放15%的数据,并且这个数字不会下降,而且我自从优化了代码以来,在任何循环中都没有变量初始化,并且在可能的情况下声明为static和final。

I've tried setting android:largeHeap="true" but it has had no visible effect so I'm looking for something that isn't a polite request to the OS and does effectively the same thing as the depreciated VMRuntime.getRuntime().setMinimumHeapSize(BIGGER_SIZE) 我尝试设置android:largeHeap="true"但是它没有明显的效果,所以我正在寻找对操作系统不是礼貌的请求,并且实际上与已贬值的VMRuntime.getRuntime().setMinimumHeapSize(BIGGER_SIZE)

I'm looking for something that isn't a polite request to the OS and does effectively the same thing as the depreciated VMRuntime.getRuntime().setMinimumHeapSize(BIGGER_SIZE) 我正在寻找对操作系统不是礼貌的请求,并且实际上与折旧的VMRuntime.getRuntime()。setMinimumHeapSize(BIGGER_SIZE)相同

There is no means to do this in the Android SDK. 在Android SDK中无法执行此操作。 Otherwise, every developer would think that they are a special snowflake and deserve 16GB of system RAM on a 512MB device. 否则,每个开发人员都将认为这是一个特殊的雪花,并且在512MB设备上应拥有16GB的系统RAM。

I've tried setting android:largeHeap="true" but it has had no visible effect 我尝试设置android:largeHeap =“ true”,但没有明显效果

You can use getMemoryClass() and getLargeMemoryClass() (on ActivityManager ) to see what the difference is in your heap limit when using android:largeHeap="true" . 您可以在ActivityManager上使用getMemoryClass()getLargeMemoryClass()来查看使用android:largeHeap="true"时堆限制的区别。 Also, bear in mind that android:largeHeap="true" is only available on API Level 11+ devices. 另外,请记住android:largeHeap="true"仅在API Level 11+设备上可用。

I've since optimized my code such that I have no variable initializations in any loops and things are declared static and final where possible. 此后,我对代码进行了优化,以使我在任何循环中都没有变量初始化,并且在可能的情况下将事物声明为静态的和最终的。

You are certainly welcome to use the DDMS Allocation Tracker, heap dumps, and the like to determine the source of your memory usage that is triggering the GC. 当然,欢迎您使用DDMS分配跟踪器,堆转储等来确定触发GC的内存使用量的来源。

If you want to avoid using largeHeap"true" there's another alternate option which is used for tweaking memory settings. 如果要避免使用largeHeap“ true”,则还有另一个替代选项可用于调整内存设置。 All you have to do is add/replace the existing line in gradle.properties file 您要做的就是在gradle.properties文件中添加/替换现有行

org.gradle.jvmargs=-Xmx1024m org.gradle.jvmargs = -Xmx1024m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM