GC.WaitForPendingFinalizers メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > GC.WaitForPendingFinalizers メソッドの意味・解説 

GC.WaitForPendingFinalizers メソッド

ファイナライザキュー処理するスレッドがそのキューを空にするまで、現在のスレッド中断します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Sub WaitForPendingFinalizers
GC.WaitForPendingFinalizers
public static void WaitForPendingFinalizers
 ()
public:
static void WaitForPendingFinalizers ()
public static void WaitForPendingFinalizers
 ()
public static function WaitForPendingFinalizers
 ()
解説解説
使用例使用例
Imports System

Namespace WaitForPendingFinalizersExample
   Class MyWaitForPendingFinalizersClass
  
    ' You can increase this number to fill up more memory.
      Private Const numMfos As
 Integer = 1000
      ' You can increase this number to cause more
      ' post-finalization work to be done.
      Private Const maxIterations As
 Integer = 100
     
      Overloads Shared Sub
 Main()
         Dim mfo As MyFinalizeObject = Nothing
      
         ' Create and release a large number of objects
         ' that require finalization.
         Dim j As Integer
         For j = 0 To numMfos - 1
            mfo = New MyFinalizeObject()
         Next j
      
         'Release the last object created in the loop.
         mfo = Nothing
      
         'Force garbage collection.
         GC.Collect()
      
         ' Wait for all finalizers to complete before continuing.
         ' Without this call to GC.WaitForPendingFinalizers, 
         ' the worker loop below might execute at the same time 
         ' as the finalizers.
         ' With this call, the worker loop executes only after
         ' all finalizers have been called.
         GC.WaitForPendingFinalizers()
      
         ' Worker loop to perform post-finalization code.
         Dim i As Integer
         For i = 0 To maxIterations - 1
            Console.WriteLine("Doing some post-finalize work")
         Next i
      End Sub
   End Class


   Class MyFinalizeObject
      ' Make this number very large to cause the finalizer to
      ' do more work.
      Private maxIterations As Integer
 = 10000
      
      Protected Overrides Sub
 Finalize()
         Console.WriteLine("Finalizing a MyFinalizeObject")
      
         ' Do some work.
         Dim i As Integer
         For i = 0 To maxIterations - 1
            ' This method performs no operation on i, but prevents 
            ' the JIT compiler from optimizing away the code inside
 
            ' the loop.
            GC.KeepAlive(i)
         Next i
         MyBase.Finalize()
      End Sub
   End Class
End Namespace
using System;

namespace WaitForPendingFinalizersExample
{
   class MyWaitForPendingFinalizersClass
   {
    // You can increase this number to fill up more memory.
    const int numMfos = 1000;
    // You can increase this number to cause more
    // post-finalization work to be done.
    const int maxIterations = 100;

    static void Main(string[]
 args)
    {
       MyFinalizeObject mfo = null;
         
       // Create and release a large number of objects
       // that require finalization.
       for(int j = 0; j < numMfos; j++)
       {
          mfo = new MyFinalizeObject();
       }
         
       //Release the last object created in the loop.
       mfo = null;

       //Force garbage collection.
       GC.Collect();
         
       // Wait for all finalizers to complete before continuing.
       // Without this call to GC.WaitForPendingFinalizers, 
       // the worker loop below might execute at the same time 
       // as the finalizers.
       // With this call, the worker loop executes only after
       // all finalizers have been called.
       GC.WaitForPendingFinalizers();

       // Worker loop to perform post-finalization code.
       for(int i = 0; i < maxIterations;
 i++)
       {
          Console.WriteLine("Doing some post-finalize work");
       }
    }
   }

   class MyFinalizeObject
   {
    // Make this number very large to cause the finalizer to
    // do more work.
    private const int maxIterations
 = 10000;
      
    ~MyFinalizeObject()
    {
       Console.WriteLine("Finalizing a MyFinalizeObject");
            
       // Do some work.
       for(int i = 0; i < maxIterations;
 i++)
       {
          // This method performs no operation on i, but prevents 
          // the JIT compiler from optimizing away the code inside 
          // the loop.
          GC.KeepAlive(i);
       }
        }
    }
}
using namespace System;
ref class MyFinalizeObject
{
private:

   // Make this number very large to cause the finalizer to
   // do more work.
   literal int maxIterations = 10000;
   ~MyFinalizeObject()
   {
      Console::WriteLine( "Finalizing a MyFinalizeObject" );
      
      // Do some work.
      for ( int i = 0; i < maxIterations;
 i++ )
      {
         
         // This method performs no operation on i, but prevents
         // the JIT compiler from optimizing away the code inside
         // the loop.
         GC::KeepAlive( i );

      }
   }

};


// You can increase this number to fill up more memory.
const int numMfos = 1000;

// You can increase this number to cause more
// post-finalization work to be done.
const int maxIterations = 100;
int main()
{
   MyFinalizeObject^ mfo = nullptr;
   
   // Create and release a large number of objects
   // that require finalization.
   for ( int j = 0; j < numMfos; j++ )
   {
      mfo = gcnew MyFinalizeObject;

   }
   
   //Release the last object created in the loop.
   mfo = nullptr;
   
   //Force garbage collection.
   GC::Collect();
   
   // Wait for all finalizers to complete before continuing.
   // Without this call to GC::WaitForPendingFinalizers,
   // the worker loop below might execute at the same time
   // as the finalizers.
   // With this call, the worker loop executes only after
   // all finalizers have been called.
   GC::WaitForPendingFinalizers();
   
   // Worker loop to perform post-finalization code.
   for ( int i = 0; i < maxIterations; i++
 )
   {
      Console::WriteLine( "Doing some post-finalize work" );

   }
}

package WaitForPendingFinalizersExample ; 

import System.* ;

class MyWaitForPendingFinalizersClass
{
    // You can increase this number to fill up more memory.
    private static final int
 numMfos = 1000;

    // You can increase this number to cause more
    // post-finalization work to be done.
    private static final int
 maxIterations = 100;

    public static void main(String[]
 args)
    {
        MyFinalizeObject mfo = null;

        // Create and release a large number of objects
        // that require finalization.
        for (int j = 0; j < numMfos; j++)
 {
            mfo = new MyFinalizeObject();
        }

        //Release the last object created in the loop.
        mfo = null;

        //Force garbage collection.
        GC.Collect();

        // Wait for all finalizers to complete before continuing.
        // Without this call to GC.WaitForPendingFinalizers, 
        // the worker loop below might execute at the same time 
        // as the finalizers.
        // With this call, the worker loop executes only after
        // all finalizers have been called.
        GC.WaitForPendingFinalizers();

        // Worker loop to perform post-finalization code.
        for (int i = 0; i < maxIterations;
 i++) {
            Console.WriteLine("Doing some post-finalize work");
        }
    } //main
} //MyWaitForPendingFinalizersClass

class MyFinalizeObject
{
    // Make this number very large to cause the finalizer to
    // do more work.
    private int maxIterations = 10000;

    public void finalize()
    {
        Console.WriteLine("Finalizing a MyFinalizeObject");

        // Do some work.
        for (int i = 0; i < maxIterations;
 i++) {
            // This method performs no operation on i, but prevents
 
            // the JIT compiler from optimizing away the code inside
 
            // the loop.
            GC.KeepAlive(new Integer(i));
        }

        try {
            super.finalize();
        }
        catch (System.Exception e) {
            Console.WriteLine(e.get_Message());
        }
    } //finalize
} //MyFinalizeObject   
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からGC.WaitForPendingFinalizers メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からGC.WaitForPendingFinalizers メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からGC.WaitForPendingFinalizers メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「GC.WaitForPendingFinalizers メソッド」の関連用語

GC.WaitForPendingFinalizers メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



GC.WaitForPendingFinalizers メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS