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)