. Net Memory Management

Source: Internet
Author: User

I have read a lot of articles about. Net memory management in the last two days, and I have learned a lot about it. So I wrote it.

. Programs generated under the. NET framework need to be compiled in real time during runtime, JIT, just in time. the code is all Il, which is easily decompiled. the framework does not need to be installed when the mono framework is running. net program needs to install the framework.

Memory Allocation is divided into managed resources and non-managed resources. unmanaged resources are located in, CPU registers, and thread stacks. we also mentioned that coroutine is different from the thread. The call time of the coroutine is determined by the programmer rather than the CPU.

Managed resources are managed by the garbage collector. divide managed resources into three generations, 0, 1, and 2 generations. the resource is initially marked as generation 0. when the zero-generation resources are insufficient, the zero-generation resources will be recycled, and the referenced memory will be reclaimed. At the same time, the zero-generation resources will be changed to the One-generation resources.

After that, the generation 0 became nervous again, and the generation 0 and generation 1 were recycled. The generation 0 changed to 1 and the generation 1 to 2. so proceed. in general, the ratio of 0-generation, 1-generation, and 2-generation recovery triggering probability is about.

I have to say that there are three garbage collection modes. the difference between them is the number of CPUs and memory size of the machine. that is, workstation concurrency is disabled, workstation concurrency is enabled, and servers are deployed. for a single CPU machine, only the workstation can be used for concurrent shutdown. In this mode, when garbage collection is performed, all other threads are suspended until the garbage collection is completed. When the workstation is enabled concurrently, multiple CPU machines are used, that is, multi-core CPU. This mode enables a separate thread for garbage collection during garbage collection. in server mode, the memory segments used for allocation are larger, so that garbage collection is not performed frequently. in addition, when the Finalize method loses reference to an object, it is called after all garbage collection is completed when garbage collection is triggered. Next time, the object was completely recycled, that is, it had to go through two garbage collections before it could be recycled.

To thoroughly understand this set of things, we need a lot of basic knowledge. It is not easy to thoroughly understand the previous things with time.

I always think. the net development environment is not suitable for me. I still like to use C ++ to handle the memory. no way. I got onto the unity thief ship at the beginning. I learned more about the idea. It is also a good thing for me. After learning the OpenGL graphics library, I will review C ++, you can develop the graphics library... hope so.

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.