1

I found that System.Exception requires many memory allocation(many Strings, 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?

Community
  • 1
  • 1
Cu2S
  • 667
  • 1
  • 5
  • 21

2 Answers2

3

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:

enter image description here

Dudi Keleti
  • 2,946
  • 18
  • 33
1

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

Cu2S
  • 667
  • 1
  • 5
  • 21