. NET memory allocation notes,. net allocation notes
Read the notes on the blog http://jonskeet.uk/csharp/memory.html( my personal skills are limited. If the translation or record is incorrect, please refer to them. Thank you ~)
Misunderstanding: the reference type is kept in the heap, and the value type is kept in the stack.
Problem: the first half is correct, and the last half is incorrect.
Storage location of Value Type:
1. Local variables are stored in the stack. In addition, variables of the reference type (not the guiding type itself, but the variable defined for storing the reference address) are also stored in the stack;
2. Global variables are stored in the heap, and are stored together with objects, with the same lifecycle;
3. the internal value type variables of the declared value type store different locations according to the defined location (a bit incompatible, the translation level is not good, the original article: instance variables for a value type are stored in the same context as the variable that declares the value type .) for example, to define a structure variable, if it is a global variable, the value type inside the structure follows 2nd; otherwise, the value type follows 1st;
4. All static variables are stored in the heap, and only one copy is retained regardless of the value type or reference type.