GC.RefreshMemoryLimit Method

Definition

Instructs the Garbage Collector to reconfigure itself by detecting the various memory limits on the system.

public:
 static void RefreshMemoryLimit();
public static void RefreshMemoryLimit ();
static member RefreshMemoryLimit : unit -> unit
Public Shared Sub RefreshMemoryLimit ()

Exceptions

The hard limit is too low. This can happen if the heap hard limit that the refresh will set, either because of new AppData settings or implied by the container memory-limit changes, is lower than what's already committed.

-or-

The hard limit is invalid. This can happen, for example, with negative heap hard-limit percentages.

Remarks

In addition to actual physical memory limit and container-limit settings, these configuration settings can be overwritten:

     - GCHeapHardLimit
     - GCHeapHardLimitPercent
     - GCHeapHardLimitSOH
     - GCHeapHardLimitLOH
     - GCHeapHardLimitPOH
     - GCHeapHardLimitSOHPercent
     - GCHeapHardLimitLOHPercent
     - GCHeapHardLimitPOHPercent

Instead of updating the environment variable (which won't be read), these override these settings by using a ulong value in the AppContext.

For example, you can use AppContext.SetData("GCHeapHardLimit", (ulong) 100 * 1024 * 1024) to override the GCHeapHardLimit to 100M.

This API only handles configs that can be handled when the runtime is loaded. For configs that don't have any effects on 32-bit systems (like the GCHeapHardLimit* ones), this API will not handle it.

Applies to