System.Runtime.MemoryFailPoint Class

Checks for sufficient memory resources before executing an operation. This class cannot be inherited.

See Also: MemoryFailPoint Members

Syntax

public sealed class MemoryFailPoint : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, IDisposable

Remarks

Note:

This class is intended for use in advanced development.

Creating an instance of the System.Runtime.MemoryFailPoint class creates a memory gate. A memory gate checks for sufficient resources before initiating an activity that requires a large amount of memory. Failing the check results in an InsufficientMemoryException exception being thrown. This exception prevents an operation from being started and reduces the possibility of failure due to lack of resources. This enables you decrease performance in an effort to avoid an OutOfMemoryException exception and any state corruption that may result from improper handling of the exception in arbitrary locations in your code.

By throwing an InsufficientMemoryException exception, an application can distinguish between an estimate that an operation will not be able to complete and a partially completed operation that may have corrupted the application state. This allows an application to reduce the frequency of a pessimistic escalation policy, which may require unloading the current AppDomain or recycling the process.

System.Runtime.MemoryFailPoint checks to see whether sufficient memory and consecutive virtual address space are available in all garbage collection heaps, and may increase the size of the swap file. System.Runtime.MemoryFailPoint makes no guarantees regarding the long-term availability of the memory during the lifetime of the gate, but callers should always use the MemoryFailPoint.Dispose method to ensure that resources associated with System.Runtime.MemoryFailPoint are released.

To use a memory gate, you must create a System.Runtime.MemoryFailPoint object and specify the number of megabytes (MB) of memory that the next operation is expected to use. If enough memory is not available, an InsufficientMemoryException exception is thrown.

The parameter of the constructor must be a positive integer. A negative value raises an ArgumentOutOfRangeException exception.

System.Runtime.MemoryFailPoint operates at a granularity of 16 MB. Any values smaller than 16 MB are treated as 16 MB, and other values are treated as the next largest multiple of 16 MB.

Requirements

Namespace: System.Runtime
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0