I'm writing a litte android app which fills the ram of a device for testing purposes. But I'm not allowed to allocate more than 512MB. The error log says:
我正在编写一个小巧的Android应用程序,它可以填充设备的内存以进行测试。但我不允许分配超过512MB。错误日志说:
Throwing OutOfMemoryError "Failed to allocate a 1000012 byte allocation with 229520 free bytes and 224KB until OOM"
Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 0% free, 511MB/512MB
Clamp target GC heap from 527MB to 512MB
I'm trying to allocate more ram after catching the oom exception - without success.
我试图在捕获oom异常后分配更多内存 - 但没有成功。
Is there a way to allocate more memory?
有没有办法分配更多的内存?
1 个解决方案
#1
2
Not in Java. Each Android app has a heap limit. Normally, that's a lot lower than 512MB; I presume that you added android:largeHeap="true"
to your manifest to get it that large.
不是Java。每个Android应用都有一个堆限制。通常,这比512MB低很多;我假设您在清单中添加了android:largeHeap =“true”以使其变大。
If you need to allocate more than that, you will need to drop down to using the NDK, as allocations made in native code do not count against the Dalvik/ART heap limit.
如果需要分配更多,则需要使用NDK,因为在本机代码中进行的分配不计入Dalvik / ART堆限制。
#1
2
Not in Java. Each Android app has a heap limit. Normally, that's a lot lower than 512MB; I presume that you added android:largeHeap="true"
to your manifest to get it that large.
不是Java。每个Android应用都有一个堆限制。通常,这比512MB低很多;我假设您在清单中添加了android:largeHeap =“true”以使其变大。
If you need to allocate more than that, you will need to drop down to using the NDK, as allocations made in native code do not count against the Dalvik/ART heap limit.
如果需要分配更多,则需要使用NDK,因为在本机代码中进行的分配不计入Dalvik / ART堆限制。