CLR via C # Reading Notes 5-2 Why not use finalize

Source: Internet
Author: User

1. When creating an object, finalize takes more time because the object needs to be put in the finalization list.

2. Finalize will make your applicationProgramIt is slower to run because additional checks are required for each object during GC.

3. Finalize will put more pressure on the memory (heap memory allocation problems)

 

4. the execution time of finalize is uncertain. If you want to use exclusive resources such as file, the person who wants to use the file cannot determine when to use the file, in this case, it is better to use dispose or close to release resources as soon as possible,

This also means that you cannot manually control the execution of finalize and its execution sequence.

 

 

PS: When to execute finalize?

1. When the 0-generation object in the managed heap is full, GC is started.

2.CodeExplicitly execute the GC. Collect Method

3. The system memory is too low.

4. Uninstall an application domain (appdomain)

5. CLR disabled

 

PS: Finalize execution timeout

The finalize execution timeout time of a single method is 2 seconds.

The total finalize time of all objects cannot exceed 40 seconds.

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.