“xx 可用字节和 xx 直到 OOM”是什么意思?

Bin*_*Bin 5 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?

geo*_*sey 2

0 可用字节的含义正如所言。我不明白的一点是3GB until next OOM

我通过 Android 源代码进行 root,在这里您会看到此错误(在 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";
Run Code Online (Sandbox Code Playgroud)

3GB 的GetFreeMemoryUntilOOME功能看起来是这样的:

// Returns approximately how much free memory we have until the next OOME happens.
size_t GetFreeMemoryUntilOOME() const {
  return growth_limit_ - GetBytesAllocated();
}
Run Code Online (Sandbox Code Playgroud)

我不确定 Growth_limit 是什么,但我读到它是最大堆大小?

这是一个糟糕的答案,我从 Android 源代码中猜测,但这里没有其他内容,所以我将发布它!