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

GC.GetTotalMemory メソッド

現在割り当てられていると思われるバイト数を取得します。このメソッド制御を戻す前に短い時間だけ待機してシステムガベージ コレクション行いオブジェクト終了操作実行できるようにするかどうかパラメータ示します

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

Public Shared Function GetTotalMemory
 ( _
    forceFullCollection As Boolean _
) As Long
Dim forceFullCollection As Boolean
Dim returnValue As Long

returnValue = GC.GetTotalMemory(forceFullCollection)
public static long GetTotalMemory (
    bool forceFullCollection
)
public:
static long long GetTotalMemory (
    bool forceFullCollection
)
public static long GetTotalMemory (
    boolean forceFullCollection
)
public static function GetTotalMemory
 (
    forceFullCollection : boolean
) : long

パラメータ

forceFullCollection

Boolean 値が true である場合、このメソッドガベージ コレクション発生するのを待機してから制御を戻すことができます

戻り値
マネージ メモリに現在割り当てられているバイト数の近似値を表す数値

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

Namespace GCCollectInt_Example
    Class MyGCCollectClass
        Private maxGarbage As Long
 = 10000

        Public Shared Sub
 Main()
            Dim myGCCol As New
 MyGCCollectClass

            'Determine the maximum number of generations the system
            'garbage collector currently supports.
            Console.WriteLine("The highest generation is {0}",
 GC.MaxGeneration)

            myGCCol.MakeSomeGarbage()

            'Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))

            'Determine the best available approximation of the number
 
            'of bytes currently allocated in managed memory.
            Console.WriteLine("Total Memory: {0}",
 GC.GetTotalMemory(False))

            'Perform a collection of generation 0 only.
            GC.Collect(0)

            'Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))

            Console.WriteLine("Total Memory: {0}",
 GC.GetTotalMemory(False))

            'Perform a collection of all generations up to and including
 2.
            GC.Collect(2)

            'Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol))
            Console.WriteLine("Total Memory: {0}",
 GC.GetTotalMemory(False))
            Console.Read()

        End Sub


        Sub MakeSomeGarbage()
            Dim vt As Version

            Dim i As Integer
            For i = 0 To maxGarbage - 1
                'Create objects and release them to fill up memory
                'with unused objects.
                vt = New Version
            Next i
        End Sub
    End Class
End Namespace
using System;

namespace GCCollectIntExample
{
    class MyGCCollectClass
    {
        private const long maxGarbage = 1000;
      
        static void Main()
        {
            MyGCCollectClass myGCCol = new MyGCCollectClass();

            // Determine the maximum number of generations the system
        // garbage collector currently supports.
            Console.WriteLine("The highest generation is {0}", GC.MaxGeneration);
            
            myGCCol.MakeSomeGarbage();

            // Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol));
            
            // Determine the best available approximation of the number
 
        // of bytes currently allocated in managed memory.
            Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false));
            
            // Perform a collection of generation 0 only.
            GC.Collect(0);
            
            // Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol));
            
            Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false));
            
            // Perform a collection of all generations up to and including
 2.
            GC.Collect(2);
            
            // Determine which generation myGCCol object is stored in.
            Console.WriteLine("Generation: {0}", GC.GetGeneration(myGCCol));
            Console.WriteLine("Total Memory: {0}", GC.GetTotalMemory(false));
            Console.Read();
        }

        void MakeSomeGarbage()
        {
            Version vt;

            for(int i = 0; i < maxGarbage;
 i++)
            {
                // Create objects and release them to fill up memory
        // with unused objects.
                vt = new Version();
            }
        }
    }
}
using namespace System;
const long maxGarbage = 1000;
ref class MyGCCollectClass
{
public:
   void MakeSomeGarbage()
   {
      Version^ vt;
      for ( int i = 0; i < maxGarbage; i++
 )
      {
         
         // Create objects and release them to fill up memory
         // with unused objects.
         vt = gcnew Version;

      }
   }

};

int main()
{
   MyGCCollectClass^ myGCCol = gcnew MyGCCollectClass;
   
   // Determine the maximum number of generations the system
   // garbage collector currently supports.
   Console::WriteLine( "The highest generation is {0}", GC::MaxGeneration
 );
   myGCCol->MakeSomeGarbage();
   
   // Determine which generation myGCCol object is stored in.
   Console::WriteLine( "Generation: {0}", GC::GetGeneration( myGCCol )
 );
   
   // Determine the best available approximation of the number
   // of bytes currently allocated in managed memory.
   Console::WriteLine( "Total Memory: {0}", GC::GetTotalMemory( false
 ) );
   
   // Perform a collection of generation 0 only.
   GC::Collect( 0 );
   
   // Determine which generation myGCCol object is stored in.
   Console::WriteLine( "Generation: {0}", GC::GetGeneration( myGCCol )
 );
   Console::WriteLine( "Total Memory: {0}", GC::GetTotalMemory( false
 ) );
   
   // Perform a collection of all generations up to and including 2.
   GC::Collect( 2 );
   
   // Determine which generation myGCCol object is stored in.
   Console::WriteLine( "Generation: {0}", GC::GetGeneration( myGCCol )
 );
   Console::WriteLine( "Total Memory: {0}", GC::GetTotalMemory( false
 ) );
}

package GCCollectIntExample; 

import System.* ;

class MyGCCollectClass
{
    private static final long maxGarbage =
 1000;

    public static void main(String[]
 args)
    {
        MyGCCollectClass myGCCol = new MyGCCollectClass();

        // Determine the maximum number of generations the system
        // garbage collector currently supports.
        Console.WriteLine("The highest generation is {0}", 
            System.Convert.ToString(GC.get_MaxGeneration()));
        myGCCol.MakeSomeGarbage();

        // Determine which generation myGCCol object is stored in.
        Console.WriteLine("Generation: {0}", 
            System.Convert.ToString(GC.GetGeneration(myGCCol)));

        // Determine the best available approximation of the number
 
        // of bytes currently allocated in managed memory.
        Console.WriteLine("Total Memory: {0}", 
            System.Convert.ToString(GC.GetTotalMemory(false)));

        // Perform a collection of generation 0 only.
        GC.Collect(0);

        // Determine which generation myGCCol object is stored in.
        Console.WriteLine("Generation: {0}", 
            System.Convert.ToString(GC.GetGeneration(myGCCol)));
        Console.WriteLine("Total Memory: {0}", 
            System.Convert.ToString(GC.GetTotalMemory(false)));

        // Perform a collection of all generations up to and including
 2.
        GC.Collect(2);

        // Determine which generation myGCCol object is stored in.
        Console.WriteLine("Generation: {0}", 
            System.Convert.ToString(GC.GetGeneration(myGCCol)));
        Console.WriteLine("Total Memory: {0}", 
            System.Convert.ToString(GC.GetTotalMemory(false)));
        Console.Read();
    } //main

    void MakeSomeGarbage()
    {
        Version vt;

        for (int i = 0; i < maxGarbage;
 i++) {
            // Create objects and release them to fill up memory
            // with unused objects.
            vt = new Version();
        }
    } //MakeSomeGarbage
} //MyGCCollectClass
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS