在我的Android应用中,我遇到了这样的异常java.lang.OutOfMemoryError: 分配32字节内存失败,0个空闲字节,直到OOM时有3GB
。0个空闲字节是什么意思?以及3GB代表什么?
在我的Android应用中,我遇到了这样的异常java.lang.OutOfMemoryError: 分配32字节内存失败,0个空闲字节,直到OOM时有3GB
。0个空闲字节是什么意思?以及3GB代表什么?
0 free bytes意味着确切的含义。我不理解的部分是3GB until next OOM
。
我查看了Android源代码,在这里可以看到此错误(在某个随机版本的Android中,我不确定是哪个版本)
oss << "Failed to allocate a " << byte_count << " byte allocation with " <<
total_bytes_free
<< " free bytes and " << PrettySize(GetFreeMemoryUntilOOME()) << " until OOM";
3GB是GetFreeMemoryUntilOOME
函数,看起来应该是这样的:
// Returns approximately how much free memory we have until the next OOME happens.
size_t GetFreeMemoryUntilOOME() const {
return growth_limit_ - GetBytesAllocated();
}
我不确定growth_limit是什么,但通过阅读我认为它是最大堆大小?
这实际上是个糟糕的答案,我只是猜测来自安卓源代码,但这里没有别的内容,所以我会发表它!