简体   繁体   中英

What happens when there is no memory to construct an OutOfMemoryException in C#?

I found that System.Exception requires many memory allocation(many String s, even IDictionary ). What happens when there is no enough memory to construct an OutOfMemoryException ?

After searching, I found a similar question: What happens when there's insufficient memory to throw an OutOfMemoryError? Does CLR behave like that?

As you (Cu2s) mentioned, the framework pre allocate some objects. The OutOfMemory is not the only one. StackOverflow of course is also needed.

See source here

And also this blog post

You can see it yourself in WinDbg or some other tool.

For example when I'm running this code:

static void Main()
{
    Console.Read();
}

I see in the heap the following:

在此处输入图片说明

I found the source code of coreclr . It seems that the CLR preallocates some exception classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM