GC.ReRegisterForFinalize メソッドとは何? わかりやすく解説 Weblio辞書

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

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

GC.ReRegisterForFinalize メソッド

SuppressFinalize が既に呼び出されている指定オブジェクトに対してファイナライザ呼び出すことをシステム要求します

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

Public Shared Sub ReRegisterForFinalize
 ( _
    obj As Object _
)
Dim obj As Object

GC.ReRegisterForFinalize(obj)
public static void ReRegisterForFinalize
 (
    Object obj
)
public:
static void ReRegisterForFinalize (
    Object^ obj
)
public static void ReRegisterForFinalize
 (
    Object obj
)
public static function ReRegisterForFinalize
 (
    obj : Object
)

パラメータ

obj

ファイナライザ呼び出し必要なオブジェクト

例外例外
例外種類条件

ArgumentNullException

objnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例
Imports System

Namespace ReRegisterForFinalizeExample
    Class MyMainClass
        Shared Sub Main()
            'Create a MyFinalizeObject.
            Dim mfo As New
 MyFinalizeObject()

            'Release the reference to mfo.
            mfo = Nothing

            'Force a garbage collection.
            GC.Collect()

            'At this point mfo will have gone through the first Finalize.
            'There should now be a reference to mfo in the static
            'MyFinalizeObject.currentInstance field.  Setting this value
            'to null and forcing another garbage collection will now
            'cause the object to Finalize permanently.
            MyFinalizeObject.currentInstance = Nothing
            GC.Collect()
        End Sub
    End Class

    Class MyFinalizeObject
        Public Shared currentInstance As
 MyFinalizeObject = Nothing
        Private hasFinalized As Boolean
 = False

        Protected Overrides Sub
 Finalize()
            If hasFinalized = False Then
                Console.WriteLine("First finalization")

                'Put this object back into a root by creating
                'a reference to it.
                MyFinalizeObject.currentInstance = Me

                'Indicate that this instance has finalized once.
                hasFinalized = True

                'Place a reference to this object back in the
                'finalization queue.
                GC.ReRegisterForFinalize(Me)
            Else
                Console.WriteLine("Second finalization")
            End If
            MyBase.Finalize()
        End Sub
    End Class
End Namespace
using System;

namespace ReRegisterForFinalizeExample
{
    class MyMainClass
    {
        static void Main()
        {
            // Create a MyFinalizeObject.
            MyFinalizeObject mfo = new MyFinalizeObject();

            // Release the reference to mfo.
            mfo = null;

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

            // At this point mfo will have gone through the first Finalize.
            // There should now be a reference to mfo in the static
            // MyFinalizeObject.currentInstance field.  Setting this
 value
            // to null and forcing another garbage collection will now
            // cause the object to Finalize permanently.
            MyFinalizeObject.currentInstance = null;
            GC.Collect();
        }
    }

    class MyFinalizeObject
    {
        public static MyFinalizeObject currentInstance
 = null;
        private bool hasFinalized = false;

        ~MyFinalizeObject()
        {
            if(hasFinalized == false)
            {
                Console.WriteLine("First finalization");
            
                // Put this object back into a root by creating
                // a reference to it.
                MyFinalizeObject.currentInstance = this;
            
                // Indicate that this instance has finalized once.
                hasFinalized = true;

                // Place a reference to this object back in the
                // finalization queue.
                GC.ReRegisterForFinalize(this);
            }
            else
            {
                Console.WriteLine("Second finalization");
            }
        }
    }
}
using namespace System;
ref class MyFinalizeObject
{
public:
   static MyFinalizeObject^ currentInstance = nullptr;

private:
   bool hasFinalized;

public:
   MyFinalizeObject()
   {
      hasFinalized = false;
   }

   ~MyFinalizeObject()
   {
      if ( hasFinalized == false )
      {
         Console::WriteLine( "First finalization" );
         
         // Put this object back into a root by creating
         // a reference to it.
         MyFinalizeObject::currentInstance = this;
         
         // Indicate that this instance has finalized once.
         hasFinalized = true;
         
         // Place a reference to this object back in the
         // finalization queue.
         GC::ReRegisterForFinalize( this );
      }
      else
      {
         Console::WriteLine( "Second finalization" );
      }
   }

};

int main()
{
   
   // Create a MyFinalizeObject.
   MyFinalizeObject^ mfo = gcnew MyFinalizeObject;
   
   // Release the reference to mfo.
   mfo = nullptr;
   
   // Force a garbage collection.
   GC::Collect();
   
   // At this point mfo will have gone through the first Finalize.
   // There should now be a reference to mfo in the static
   // MyFinalizeObject::currentInstance field.  Setting this value
   // to 0 and forcing another garbage collection will now
   // cause the object to Finalize permanently.
   MyFinalizeObject::currentInstance = nullptr;
   GC::Collect();
}

package ReRegisterForFinalizeExample;

import System.* ;

class MyMainClass
{
    public static void main(String[]
 args)
    {
        // Create a MyFinalizeObject.
        MyFinalizeObject mfo = new MyFinalizeObject();

        // Release the reference to mfo.
        mfo = null;

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

        // At this point mfo will have gone through the first Finalize.
        // There should now be a reference to mfo in the static
        // MyFinalizeObject.currentInstance field.  Setting this value
        // to null and forcing another garbage collection will now
        // cause the object to Finalize permanently.
        MyFinalizeObject.currentInstance = null;
        GC.Collect();
    } //main
} //MyMainClass

class MyFinalizeObject
{
    public static MyFinalizeObject currentInstance
 = null;
    private boolean hasFinalized = false;

    public void finalize()
    {
        if (hasFinalized == false) {
            Console.WriteLine("First finalization");

            // Put this object back into a root by creating
            // a reference to it.
            MyFinalizeObject.currentInstance = this;

            // Indicate that this instance has finalized once.
            hasFinalized = true;

            // Place a reference to this object back in the
            // finalization queue.
            GC.ReRegisterForFinalize(this);
        }
        else {
            Console.WriteLine("Second finalization");
        }

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



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS