GC.WaitForFullGCApproach メソッド

定義

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための、登録済みの通知の状態を返します。

オーバーロード

WaitForFullGCApproach()

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための、登録済みの通知の状態を返します。

WaitForFullGCApproach(Int32)

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための登録済みの通知の状態を、指定したタイムアウト時間で返します。

WaitForFullGCApproach(TimeSpan)

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための登録済みの通知の状態を、指定したタイムアウト時間で返します。

WaitForFullGCApproach()

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

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための、登録済みの通知の状態を返します。

public:
 static GCNotificationStatus WaitForFullGCApproach();
public static GCNotificationStatus WaitForFullGCApproach ();
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCApproach ();
static member WaitForFullGCApproach : unit -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCApproach : unit -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach () As GCNotificationStatus

戻り値

登録済みのガベージ コレクションの通知の状態。

属性

次の例は、このメソッドを使用して、完全なブロッキング ガベージ コレクションが近づいているかどうかを判断する方法を示しています。 通知の状態が である場合は Succeeded常に、 ユーザー メソッド OnFullGCApproachNotify が呼び出され、近づいているコレクションに応答してアクションが実行されます。 このコード例は、 ガベージ コレクション通知 に関するトピックで提供されるより大きな例の一部です。

// Check for a notification of an approaching collection.
GCNotificationStatus s = GC::WaitForFullGCApproach();
if (s == GCNotificationStatus::Succeeded)
{
    Console::WriteLine("GC Notifiction raised.");
    OnFullGCApproachNotify();
}
else if (s == GCNotificationStatus::Canceled)
{
    Console::WriteLine("GC Notification cancelled.");
    break;
}
else
{
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    Console::WriteLine("GC Notification not applicable.");
    break;
}
// Check for a notification of an approaching collection.
GCNotificationStatus s = GC.WaitForFullGCApproach();
if (s == GCNotificationStatus.Succeeded)
{
    Console.WriteLine("GC Notification raised.");
    OnFullGCApproachNotify();
}
else if (s == GCNotificationStatus.Canceled)
{
    Console.WriteLine("GC Notification cancelled.");
    break;
}
else
{
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    Console.WriteLine("GC Notification not applicable.");
    break;
}
// Check for a notification of an approaching collection.
match GC.WaitForFullGCApproach() with
| GCNotificationStatus.Succeeded ->
    printfn "GC Notification raised."
    onFullGCApproachNotify ()
    // Check for a notification of a completed collection.
    match GC.WaitForFullGCComplete() with
    | GCNotificationStatus.Succeeded ->
        printfn "GC Notification raised."
        onFullGCCompleteEndNotify ()
    | GCNotificationStatus.Canceled ->
        printfn "GC Notification cancelled."
        broken <- true
    | _ ->
        // Could be a time out.
        printfn "GC Notification not applicable."
        broken <- true
| GCNotificationStatus.Canceled ->
    printfn "GC Notification cancelled."
    broken <- true
| _ ->
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    printfn "GC Notification not applicable."
    broken <- true
' Check for a notification of an approaching collection.
Dim s As GCNotificationStatus = GC.WaitForFullGCApproach
If (s = GCNotificationStatus.Succeeded) Then
    Console.WriteLine("GC Notification raised.")
    OnFullGCApproachNotify()
ElseIf (s = GCNotificationStatus.Canceled) Then
    Console.WriteLine("GC Notification cancelled.")
    Exit While
Else
    ' This can occur if a timeout period
    ' is specified for WaitForFullGCApproach(Timeout) 
    ' or WaitForFullGCComplete(Timeout)  
    ' and the time out period has elapsed. 
    Console.WriteLine("GC Notification not applicable.")
    Exit While
End If

注釈

メソッドを GCNotificationStatus 使用して登録された現在のガベージ コレクション通知の状態を確認するには、このメソッドによって返される列挙体を RegisterForFullGCNotification 使用します。 メソッドを WaitForFullGCComplete 使用して、完全なガベージ コレクションが完了したかどうかを確認することもできます。

列挙が を返 Succeededす場合は、追加のオブジェクトが割り当てられないようにしたり、 メソッドを使用してコレクションを自分で誘導したりなどのタスクを Collect 実行できます。 通知では、完全なガベージ コレクションが発生することは保証されず、完全なガベージ コレクションが発生するのに適したしきい値に達した条件に達しただけです。

このメソッドは、ガベージ コレクション通知が取得されるまで無期限に待機します。 通知を取得できない場合にメソッドが返すタイムアウト期間を指定する場合は、 メソッド オーバーロードを使用します GC.WaitForFullGCApproach(Int32) 。 タイムアウトを指定せずにこのメソッドを呼び出す場合は、優先よりも長く待機している場合に メソッドを呼び出 CancelFullGCNotification すことができます。

完全なガベージ コレクションがあることを確認するには、 メソッドの WaitForFullGCComplete 呼び出しでこのメソッドに従う必要があります。 このメソッドのみを呼び出すと、不確定な結果が発生します。

こちらもご覧ください

適用対象

WaitForFullGCApproach(Int32)

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

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための登録済みの通知の状態を、指定したタイムアウト時間で返します。

public:
 static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout);
public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout);
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout);
static member WaitForFullGCApproach : int -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCApproach : int -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach (millisecondsTimeout As Integer) As GCNotificationStatus

パラメーター

millisecondsTimeout
Int32

通知の状態が取得されるまで待機する時間。 無期限に待機するには -1 を指定します。

戻り値

登録済みのガベージ コレクションの通知の状態。

属性

例外

millisecondsTimeout は、 Int32.MaxValue または -1 以下である必要があります。

注釈

メソッドを GCNotificationStatus 使用して登録された現在のガベージ コレクション通知の状態を確認するには、このメソッドによって返される列挙体を RegisterForFullGCNotification 使用します。 メソッドを WaitForFullGCComplete 使用して、完全なガベージ コレクションが完了したかどうかを確認することもできます。

このメソッドは、 で millisecondsTimeout指定された値に関係なく、ガベージ コレクションの通知状態が取得されるたびに直ちに返されることに注意してください。 タイムアウトする前に millisecondsTimeout ガベージ コレクションの通知状態が取得されない場合、このメソッドは を返します NotApplicable

列挙が を返 Succeededす場合は、追加のオブジェクトが割り当てられないようにしたり、 メソッドを使用してコレクションを自分で誘導したりなどのタスクを Collect 実行できます。 通知では、完全なガベージ コレクションが発生することは保証されず、完全なガベージ コレクションが発生するのに適したしきい値に達した条件に達しただけです。

タイムアウト期間が CancelFullGCNotification 経過するまで待機できない場合は、 メソッドを呼び出すことができます。

完全なガベージ コレクションがあることを確認するには、 メソッドの WaitForFullGCComplete 呼び出しでこのメソッドに従う必要があります。 このメソッドのみを呼び出すと、不確定な結果が発生します。

こちらもご覧ください

適用対象

WaitForFullGCApproach(TimeSpan)

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

共通言語ランタイムによるフル ブロッキング ガベージ コレクションが近づいているかどうかを確認するための登録済みの通知の状態を、指定したタイムアウト時間で返します。

public:
 static GCNotificationStatus WaitForFullGCApproach(TimeSpan timeout);
public static GCNotificationStatus WaitForFullGCApproach (TimeSpan timeout);
static member WaitForFullGCApproach : TimeSpan -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach (timeout As TimeSpan) As GCNotificationStatus

パラメーター

timeout
TimeSpan

完全な GC アプローチを待機するときのタイムアウト

戻り値

登録済みの完全 GC 通知の状態

適用対象