“xx free bytes和xx直到OOM”是什么意思?

时间:2015-05-14 10:31:28

标签: java android out-of-memory

我的Android应用java.lang.OutOfMemoryError: Failed to allocate a 32 byte allocation with 0 free bytes and 3GB until OOM出现了这样的异常。 0个空闲字节是什么意思?和3GB?

1 个答案:

答案 0 :(得分:1)

0个空闲字节意味着确切的含义。我不明白的是3GB until next OOM

我扎根于Android源码,在这里您会看到此错误(在某些随机版本的Android中,我不确定哪个错误)

https://android.googlesource.com/platform/art/+/dd162fb5990cedf80a5093ecc0e77df82af5f754/runtime/gc/heap.cc#872

 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,但是从读取的内容来看,这是最大堆大小?

从Android来源猜测,这确实是一个可怕的答案,但是这里没有别的了,所以我将其发布!