Bewerken

Share via


GC.TryStartNoGCRegion Method

Definition

Attempts to disallow garbage collection during the execution of a critical path.

Overloads

TryStartNoGCRegion(Int64, Int64, Boolean)

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

TryStartNoGCRegion(Int64, Int64)

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap.

TryStartNoGCRegion(Int64, Boolean)

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

TryStartNoGCRegion(Int64)

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available.

Remarks

Important

You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. In other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

TryStartNoGCRegion(Int64, Int64, Boolean)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

public:
 static bool TryStartNoGCRegion(long totalSize, long lohSize, bool disallowFullBlockingGC);
public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC);
static member TryStartNoGCRegion : int64 * int64 * bool -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * int64 * bool -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, lohSize As Long, disallowFullBlockingGC As Boolean) As Boolean

Parameters

totalSize
Int64

The amount of memory in bytes to allocate without triggering a garbage collection. totalSize -lohSize must be less than or equal to the size of an ephemeral segment. For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

lohSize
Int64

The number of bytes in totalSize to use for large object heap (LOH) allocations.

disallowFullBlockingGC
Boolean

true to omit a full blocking garbage collection if the garbage collector is initially unable to allocate the specified memory on the small object heap (SOH) and LOH; otherwise, false.

Returns

true if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

Attributes

Exceptions

totalSize - lohSize exceeds the ephemeral segment size.

The process is already in no GC region latency mode.

Remarks

The TryStartNoGCRegion(Int64, Int64, Boolean) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. If the runtime is unable to initially allocate the requested amount of memory and the disallowFullBlockingGC argument is false, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory; otherwise, the allocation fails, and the method returns false. The garbage collector enters no GC region latency mode if it is able to allocate lohSize for the LOH and totalSize - lohSize for the small object heap (SOH).

lohSize must be large enough to handle all memory allocations that occur in the critical path for the LOH, and totalSize - lohSize must be large enough to handle all memory allocations that occur in the critical path for the SOH. This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

Setting disallowFullBlockingGC to true to prevent a full blocking garbage collection if not enough memory is initially available is most useful in load balancing scenarios: one system can call this method and report itself as ready to accept requests if it returns true, and have the load balancer redirect requests to other systems if it returns false. It can then do a full blocking garbage collection when it's not handling requests by calling the Collect(Int32, GCCollectionMode, Boolean, Boolean) method.

Important

You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. In other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

You exit the no GC region latency mode by calling the EndNoGCRegion method.

See also

Applies to

TryStartNoGCRegion(Int64, Int64)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap.

public:
 static bool TryStartNoGCRegion(long totalSize, long lohSize);
public static bool TryStartNoGCRegion (long totalSize, long lohSize);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, long lohSize);
static member TryStartNoGCRegion : int64 * int64 -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * int64 -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, lohSize As Long) As Boolean

Parameters

totalSize
Int64

The amount of memory in bytes to allocate without triggering a garbage collection. totalSize -lohSize must be less than or equal to the size of an ephemeral segment. For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

lohSize
Int64

The number of bytes in totalSize to use for large object heap (LOH) allocations.

Returns

true if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

Attributes

Exceptions

totalSize - lohSize exceeds the ephemeral segment size.

The process is already in no GC region latency mode.

Remarks

The TryStartNoGCRegion(Int64, Int64) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. If the runtime is unable to initially allocate the requested amount of memory, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory. The garbage collector enters no GC region latency mode if it is able to allocate lohSize for the LOH and totalSize - lohSize for the small object heap (SOH).

lohSize must be large enough to handle all memory allocations that occur in the critical path for the LOH, and totalSize - lohSize must be large enough to handle all memory allocations that occur in the critical path for the SOH. This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

Important

You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. In other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

You exit the no GC region latency mode by calling the EndNoGCRegion method.

See also

Applies to

TryStartNoGCRegion(Int64, Boolean)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

public:
 static bool TryStartNoGCRegion(long totalSize, bool disallowFullBlockingGC);
public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC);
static member TryStartNoGCRegion : int64 * bool -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * bool -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, disallowFullBlockingGC As Boolean) As Boolean

Parameters

totalSize
Int64

The amount of memory in bytes to allocate without triggering a garbage collection. It must be less than or equal to the size of an ephemeral segment. For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

disallowFullBlockingGC
Boolean

true to omit a full blocking garbage collection if the garbage collector is initially unable to allocate totalSize bytes; otherwise, false.

Returns

true if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

Attributes

Exceptions

totalSize exceeds the ephemeral segment size.

The process is already in no GC region latency mode.

Remarks

The TryStartNoGCRegion(Int64, Boolean) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. If the runtime is unable to initially allocate the requested amount of memory and the disallowFullBlockingGC argument is false, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory; otherwise, the allocation fails, and the method returns false. The garbage collector enters no GC region latency mode if it is able to allocate the required amount of memory, which in this case is actually 2 * totalSize (it attempts to allocate totalSize for the small object heap and totalSize for the large object heap).

totalSize must be large enough to handle all memory allocations that occur in the critical path. This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

Setting disallowFullBlockingGC to true to prevent a full blocking garbage collection if not enough memory is initially available is most useful in load balancing scenarios: one system can call this method and report itself as ready to accept requests if it returns true, and have the load balancer redirect requests to other systems if it returns false. It can then do a full blocking garbage collection when it's not handling requests by calling the Collect(Int32, GCCollectionMode, Boolean, Boolean) method.

Important

You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. In other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

You exit the no GC region latency mode by calling the EndNoGCRegion method.

See also

Applies to

TryStartNoGCRegion(Int64)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available.

public:
 static bool TryStartNoGCRegion(long totalSize);
public static bool TryStartNoGCRegion (long totalSize);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize);
static member TryStartNoGCRegion : int64 -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long) As Boolean

Parameters

totalSize
Int64

The amount of memory in bytes to allocate without triggering a garbage collection. It must be less than or equal to the size of an ephemeral segment. For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

Returns

true if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

Attributes

Exceptions

totalSize exceeds the ephemeral segment size.

The process is already in no GC region latency mode.

Remarks

The TryStartNoGCRegion(Int64) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. If the runtime is unable to initially allocate the requested amount of memory, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory. The garbage collector enters no GC region latency mode if it is able to allocate the required amount of memory, which in this case is actually 2 * totalSize bytes (it attempts to allocate totalSize bytes for the small object heap and totalSize bytes for the large object heap).

totalSize must be large enough to handle all memory allocations that occur in the critical path. This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

Important

You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. In other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

You exit the no GC region latency mode by calling the EndNoGCRegion method.

See also

Applies to