c# - C#中构造OutOfMemoryException没有内存时会发生什么?

标签 c# .net clr

我发现 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();
}

我在堆中看到以下内容:

enter image description here

关于c# - C#中构造OutOfMemoryException没有内存时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37370025/

相关文章:

c# - 为什么使用 Interaction.Shell 方法会出现文件未找到异常?

C# vb : System. Func占用多少内存?

.net - Json.NET 与 .NET 4.6 的兼容性

c# - 使用 PropertyInfo 找出属性类型

debugging - 由于 "code is optimized"异常,无法使用 Mdbg 进行 func-eval

c# - 在 LINQ to SQL 中执行 InsertOnSubmit 时出现 NullReferenceException

c# - 如何正确编写异步方法?

c# - ASP.Net 2012 使用 jQuery 进行不显眼的验证

sql-server - SQL CLR 拆分 UDF 中的标识列

c# - .Net CLR 如何在内部实现 "Interface"?