. NET memory allocation notes,. net allocation notes

Source: Internet
Author: User

. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.