C # Dispose Finalize

Source: Internet
Author: User
Tags finally block

Documents worth Reference: Http://www.jb51.net/article/37214.htm.

. NET Memory Management process:

The managed heap assumes that the memory is infinitely large and linearly continuously allocates memory;

When the actual memory is not enough to use, traverse the managed heap to the resource and mark the expired resource;

Compresses the managed heap after the tagged resource is removed (again from the beginning), adjusting the heap pointer to the beginning of the free memory;

Other:

Garbage collection is primarily and Microsoft recommends that the CLR do it itself, and it is not recommended to use GC. Collect directive;

You are responsible for the recycling of unmanaged resources:

  • Finalize: Recycles unmanaged resources within Finalize to ensure that the CLR calls Finalize to reclaim unmanaged resources when memory is reclaimed;
  • Dispose: To provide an explicit interface, the primary motive for using Dispose is to mate with using, and the compiler will automatically generate a try.finally block for the using, and the compiler will convert the variables in the using to IDispose and call the Di at finally Spose;

  

  

  

C # Dispose Finalize

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.