添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
慷慨的铁板烧  ·  Fixing ...·  1 周前    · 
鼻子大的人字拖  ·  How to Prevent Out of ...·  1 周前    · 
善良的香烟  ·  5.6 Out-of-bounds ...·  1 周前    · 
暴躁的人字拖  ·  Automatically detect ...·  1 周前    · 
很酷的南瓜  ·  GC.GetTotalMemory(Bool ...·  6 天前    · 
完美的鸡蛋面  ·  Send push tokens | ...·  3 月前    · 
傻傻的毛豆  ·  WP Mail SMTP Not ...·  7 月前    · 

このブラウザーはサポートされなくなりました。

Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。

Microsoft Edge をダウンロードする Internet Explorer と Microsoft Edge の詳細情報
public:
 static long GetTotalMemory(bool forceFullCollection);
public static long GetTotalMemory(bool forceFullCollection);
static member GetTotalMemory : bool -> int64
Public Shared Function GetTotalMemory (forceFullCollection As Boolean) As Long

パラメーター

次の例では、 メソッドを GetTotalMemory 使用して、マネージド メモリに現在割り当てられているバイト数を取得および表示する方法を示します。

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 ) );
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();
open System
let maxGarbage = 1000
type MyGCCollectClass() =
    member _.MakeSomeGarbage() =
        for _ = 1 to maxGarbage do
            // Create objects and release them to fill up memory with unused objects.
            Version() |> ignore
[<EntryPoint>]
let main _ =
    let myGCCol = MyGCCollectClass()
    // Determine the maximum number of generations the system
    // garbage collector currently supports.
    printfn $"The highest generation is {GC.MaxGeneration}"
    myGCCol.MakeSomeGarbage()
    // Determine which generation myGCCol object is stored in.
    printfn $"Generation: {GC.GetGeneration myGCCol}"
    // Determine the best available approximation of the number
    // of bytes currently allocated in managed memory.
    printfn $"Total Memory: {GC.GetTotalMemory false}"
    // Perform a collection of generation 0 only.
    GC.Collect 0
    // Determine which generation myGCCol object is stored in.
    printfn $"Generation: {GC.GetGeneration myGCCol}"
    printfn $"Total Memory: {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.
    printfn $"Generation: {GC.GetGeneration myGCCol}"
    printfn $"Total Memory: {GC.GetTotalMemory false}"
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
	

パラメーターが の場合、 forceFullCollection このメソッドは true、システムがガベージ を収集してオブジェクトを最終処理する間、短い間隔で待機してから を返します。 間隔の期間は、完了したガベージ コレクション サイクルの数と、サイクル間で回復されるメモリの量の変化によって決まる、内部的に指定された制限です。 ガベージ コレクターでは、アクセスできないすべてのメモリが収集されるとは限りません。