简体   繁体   English

Robolectric Java堆大小错误

[英]Robolectric java heap size error

So I am running my tests using Robolectric 3.1.4. 因此,我使用Robolectric 3.1.4运行测试。 In another project I had no problems running all my test with robolectric, but right now I always get this error: 在另一个项目中,使用robolectric运行所有测试都没有问题,但是现在我总是会收到此错误:

java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError:Java堆空间

When I remove some views of the activity, the problem stops... 当我删除活动的某些视图时,问题停止了……

Well, my question is: How can I increase the heap size in the project or how can I make robolectric consume less memory? 好吧,我的问题是:如何增加项目中的堆大小或如何使robolectric消耗更少的内存?

Any help is appreciated! 任何帮助表示赞赏!

This kind of problem usually happens when you're displaying too many images on your activities. 当您在活动中显示太多图像时,通常会发生这种问题。 Probably using some ViewPager? 可能使用一些ViewPager? If that's the case, you can read this , which explains how to use cache to store images and reduce memory consumption. 如果是这样,您可以阅读this ,它解释了如何使用缓存来存储图像并减少内存消耗。

Another solution is increasing the heap size, by setting this on the AndroidManifest.xml: android:largeHeap=”true” .. But keep in mind that this is used mostly on apps that require a lot of memory like games, video processors, etc 另一个解决方案是通过在AndroidManifest.xml上进行设置来增加堆大小: android:largeHeap=”true” ..但是请记住,这主要用于需要大量内存的应用程序,例如游戏,视频处理器等。

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

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