tags:

views:

166

answers:

3

I have a class which have a static member. As I understand all static members are common for all instance of the class. So it means static members would get memory only once. Where is this memory is allocated (Stack or Heap) and when this memory get allocated.

EDIT: This memory is different from a instance level memory. How this memory get referenced. and Do this memory get allocated at the time of compilation

A: 

This memory as allocated on heap. Each type has static constructor which performs initialization of the type. It is executed before type is accessed.

Andrew Bezzub
This memory is different from a instance level memory. How this memory get referenced. and Do this memory get allocated at the time of compilation.
vaibhav
+2  A: 

Static members are always stored in the global heap, even reference type members. However, this heap is not the normal garbage collected heap. Find out more here: http://www.codeproject.com/KB/cs/codeconcepts.aspx

Simeon
+1  A: 

The memory allocation for static members is done just when the type is used for the time, be it as declaration for a variable or access to a static member.

As already statet, memory allocation for static members is done on the heap.

BeowulfOF