Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

static class allocation

Tags:

c#

class

static

In C# are static classes stack allocated?

Since they cannot be instantiated, I guess that must the how it is done.

like image 892
Tony The Lion Avatar asked Jun 25 '10 11:06

Tony The Lion


2 Answers

They're stored inside the area of the heap called the High Frequency Heap. You can find more details in this codeproject article. Static Keyword Demystified

like image 168
Hans Olsson Avatar answered Sep 22 '22 10:09

Hans Olsson


My understanding is that static classes are allocated on the heap (using the static constructor, when the type is initialised).

If they were on the stack, you'd run out of stack space very quickly, if you had a lot of static classes kicking around.

like image 36
Rowland Shaw Avatar answered Sep 22 '22 10:09

Rowland Shaw