CLR via C # Reading Notes 5-5 reserved large memory

Source: Internet
Author: User

Outofmemoryexception is very likely to occur when computing requires a lot of memory space.

System. runtime. memoryfailpoint provides the memory check function before running computation that requires large memory.

When calling this method, perform the following steps (if you do not fully determine the size of the required memory, you can pass an approximate value)

1. Check whether the system's page files have sufficient available space and whether there is sufficient continuous virtual address space in the process.

2. If there is not enough space, GC will be started to try to recycle some memory.

3. If there is still not enough page file space after GC, try to expand the page file. If the page file size still cannot meet the requirements, an insufficientmemoryexception will be thrown.

4. If the process does not have enough continuous virtual address space, an insufficientmemoryexception is thrown.

5. If there is sufficient memory and continuous virtual address space, the required memory will be reserved and the value representing the memory size will be added to a static field of memoryfailpoint.

6. operations are thread-safe.

PS: insufficientmemoryexception inherits from outofmemoryexception

If no insufficientmemoryexception is thrown during the operation, it indicates that you have reserved enough memory for your computing, but these memories have not been physically allocated to you, this means that successful reserved memory does not mean yourProgramIt must be executed successfully. This class is used to help you write more robust programs.

 

In addition, you need to call memoryfailpoint. Dispose when the operation is complete (this method reduces the field that saved the value just now)

 

 

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.