GC.GetTotalMemory メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim forceFullCollection As Boolean Dim returnValue As Long returnValue = GC.GetTotalMemory(forceFullCollection)
戻り値
マネージ メモリに現在割り当てられているバイト数の近似値を表す数値。

forceFullCollection が 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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGC.GetTotalMemory メソッドを検索する場合は、下記のリンクをクリックしてください。

- GC.GetTotalMemory メソッドのページへのリンク