C # managed versus unmanaged

Source: Internet
Author: User

To carry out the article, we need to clarify two concepts first.


The first one is that many people use. NET write programs that talk to the concept of hosting. So. NET what does the resource escrow mean, relative to all resources, or only to a certain aspect of resources? A lot of people don't know much about this, actually. NET refers to the host is only for the memory of this aspect, not for all resources, so for stream, database connection, GDI + related objects, as well as COM objects, and so on, these resources are not subject to. NET management, collectively referred to as unmanaged resources. For memory release and recovery, the system provides gc-garbage Collector, while other resources need to be released manually.

Then the second concept is what is rubbish, through my previous articles, will understand. NET types fall into two categories, one is a value type and the other is a reference type. The former is allocated on the stack and does not require GC reclamation; the latter is allocated on the heap, so its memory release and recycling needs to be done by GC. GC is all called "garbage Collector", as the name implies is the garbage collector, then only the object called garbage can be recycled by GC. That is, the memory used by a reference type object needs to be reclaimed by GC and needs to be garbage first. So. NET how to determine a reference type object is garbage,. NET's judgment is simple, as long as the object or its contained sub-object is determined that no reference is valid, then the system considers it to be garbage.

With these two basic concepts in view, let's talk about how GC works and how it functions. The release and recycling of memory needs to accompany the program's operation, so the system arranges separate threads for the GC. The GC's work is, in general, querying whether objects in memory become garbage, and then releasing and recycling the garbage. Then the GC takes a certain priority algorithm for memory recycling to recycle memory resources. Second, there are two kinds of garbage in memory, one is to call the destructor of the object, and the other is not to call. GC for the former recycling needs to be done in two steps, the first step is to call the object's destructor, the second step is to reclaim the memory, but note that these two steps are not in the GC round-robin completed, that is, two cycles of rotation, in contrast to the latter, it is only to reclaim memory.

C # managed versus unmanaged

Related Article

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.