我发现 System.Exception 需要很多内存分配(很多 String,甚至 IDictionary)。当没有足够的内存来构造 OutOfMemoryException 时会发生什么?
搜索后发现了一个类似的问题:What happens when there's insufficient memory to throw an OutOfMemoryError? CLR 有这样的行为吗?
请您参考如下方法:
正如您 (Cu2s) 提到的,框架预先分配了一些对象。 OutOfMemory 不是唯一的一个。 StackOverflow当然也是需要的。
参见来源 here
还有这个blog post
您可以在 WinDbg 或其他工具中自行查看。
例如,当我运行这段代码时:
static void Main()
{
Console.Read();
}
我在堆中看到以下内容:
