GC.Collect Yöntem

Tanım

Çöp toplamayı zorlar.Forces garbage collection.

Aşırı Yüklemeler

Collect()

Tüm nesiller için anında atık toplamayı zorlar.Forces an immediate garbage collection of all generations.

Collect(Int32)

Bir atık toplamayı, belirtilen nesil 0 ' dan oluşturma aşamasından zorlar.Forces an immediate garbage collection from generation 0 through a specified generation.

Collect(Int32, GCCollectionMode)

Bir atık toplamayı, bir değer tarafından belirtilen bir oluşturma yoluyla, belirli bir nesil 0 ' dan oluşturma işlemini zorlar GCCollectionMode .Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value.

Collect(Int32, GCCollectionMode, Boolean)

Bir atık toplamayı, bir değer tarafından belirtilen bir kez, belirtilen bir oluşturma aracılığıyla 0. kuşak ile, GCCollectionMode koleksiyonun engellenip engellenmeyeceğini belirten bir değerle zorlar.Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value, with a value specifying whether the collection should be blocking.

Collect(Int32, GCCollectionMode, Boolean, Boolean)

Bir atık toplamayı, bir değer tarafından belirtilen bir kez, belirtilen bir oluşturma yoluyla, bir değerle belirtilen bir zamanda, GCCollectionMode koleksiyonun engellenip engellenmeyeceğini ve sıkıştırılmasını belirten değerlerle zorlar.Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value, with values that specify whether the collection should be blocking and compacting.

Collect()

Tüm nesiller için anında atık toplamayı zorlar.Forces an immediate garbage collection of all generations.

public:
 static void Collect();
public static void Collect ();
static member Collect : unit -> unit
Public Shared Sub Collect ()

Örnekler

Aşağıdaki örnek, Collect tüm bellek oluşumlarında bir koleksiyon gerçekleştirmek için yönteminin nasıl kullanılacağını gösterir.The following example demonstrates how to use the Collect method to perform a collection on all generations of memory. Kod, kullanılmamış sayıda nesne üretir ve sonra Collect bunları bellekten temizlemek için yöntemini çağırır.The code generates a number of unused objects, and then calls the Collect method to clean them from memory.

using namespace System;

const int maxGarbage = 1000;

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;
   }
}

void main()
{
   // Put some objects in memory.
   MakeSomeGarbage();
   Console::WriteLine("Memory used before collection:       {0:N0}", 
                      GC::GetTotalMemory( false ) );
   
   // Collect all generations of memory.
   GC::Collect();
   Console::WriteLine("Memory used after full collection:   {0:N0}", 
                      GC::GetTotalMemory( true ) );
}
// The output from the example resembles the following:
//       Memory used before collection:       79,392
//       Memory used after full collection:   52,640
using System;

class MyGCCollectClass
{
   private const int maxGarbage = 1000;

   static void Main()
   {
      // Put some objects in memory.
      MyGCCollectClass.MakeSomeGarbage();
      Console.WriteLine("Memory used before collection:       {0:N0}",
                        GC.GetTotalMemory(false));

      // Collect all generations of memory.
      GC.Collect();
      Console.WriteLine("Memory used after full collection:   {0:N0}",
                        GC.GetTotalMemory(true));
   }

   static void MakeSomeGarbage()
   {
      Version vt;

      // Create objects and release them to fill up memory with unused objects.
      for(int i = 0; i < maxGarbage; i++) {
         vt = new Version();
      }
   }
}
// The output from the example resembles the following:
//       Memory used before collection:       79,392
//       Memory used after full collection:   52,640
Class MyGCCollectClass
     Private Const maxGarbage As Integer = 1000

     Shared Sub Main()
         'Put some objects in memory.
         MyGCCollectClass.MakeSomeGarbage()
         Console.WriteLine("Memory used before collection:       {0:N0}", 
                           GC.GetTotalMemory(False))

         'Collect all generations of memory.
         GC.Collect()
         Console.WriteLine("Memory used after full collection:   {0:N0}", 
                           GC.GetTotalMemory(True))
     End Sub

     Shared 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 
     End Sub
 End Class
' The output from the example resembles the following:
'       Memory used before collection:       79,392
'       Memory used after full collection:   52,640

Açıklamalar

Erişilemeyen tüm belleği geri almaya çalışmak için bu yöntemi kullanın.Use this method to try to reclaim all memory that is inaccessible. Tüm nesiller için engelleyici bir çöp toplama işlemi gerçekleştirir.It performs a blocking garbage collection of all generations.

Tüm nesneler, bellekte ne kadar süreyle olduklarına bakılmaksızın koleksiyon için kabul edilir; Ancak, yönetilen kodda başvurulan nesneler toplanmaz.All objects, regardless of how long they have been in memory, are considered for collection; however, objects that are referenced in managed code are not collected. Sistemin kullanılabilir bellek miktarı üst sınırını geri almaya çalışmaya zorlamak için bu yöntemi kullanın.Use this method to force the system to try to reclaim the maximum amount of available memory.

.NET Framework 4.5.1 ile başlayarak, GCSettings.LargeObjectHeapCompactionMode GCLargeObjectHeapCompactionMode.CompactOnce Aşağıdaki örnekte gösterildiği gibi, yöntemi çağırmadan önce özelliğini ayarlayarak büyük nesne yığınını (LOH) sıkıştırabilirsiniz Collect .Starting with the .NET Framework 4.5.1, you can compact the large object heap (LOH) by setting the GCSettings.LargeObjectHeapCompactionMode property to GCLargeObjectHeapCompactionMode.CompactOnce before calling the Collect method, as the following example illustrates.

GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();      
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce
GC.Collect()      

Şunlara uygulanır

Collect(Int32)

Bir atık toplamayı, belirtilen nesil 0 ' dan oluşturma aşamasından zorlar.Forces an immediate garbage collection from generation 0 through a specified generation.

public:
 static void Collect(int generation);
public static void Collect (int generation);
static member Collect : int -> unit
Public Shared Sub Collect (generation As Integer)

Parametreler

generation
Int32

Atık olarak toplanabilecek en eski oluşturma sayısı.The number of the oldest generation to be garbage collected.

Özel durumlar

generation geçerli değil.generation is not valid.

Örnekler

Aşağıdaki örnek, Collect her bir bellek katmanında bir koleksiyon gerçekleştirmek için yönteminin nasıl kullanılacağını gösterir.The following example demonstrates how to use the Collect method to perform a collection on individual layers of memory. Kod, kullanılmamış sayıda nesne üretir ve sonra Collect bunları bellekten temizlemek için yöntemini çağırır.The code generates a number of unused objects, and then calls the Collect method to clean them from memory.

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();
            }
        }
    }
}
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

Açıklamalar

Erişilemeyen belleği geri almaya çalışmak için bu yöntemi kullanın.Use this method to try to reclaim memory that is inaccessible. Ancak, bu yöntemin kullanılması, belirtilen neslin tüm erişilemeyen belleğin geri kazanılabileceğini garanti etmez.However, using this method does not guarantee that all inaccessible memory in the specified generation is reclaimed.

Nesne eskime 'i uygulanmışsa, atık toplayıcı, belirtilen nesden yüksek bir oluşturma numarası olan nesneleri toplamaz.If object aging is implemented, the garbage collector does not collect objects with a generation number that is higher than the specified generation. Nesne eskime, uygulanmadıklarında, çöp toplayıcı çöp toplama sırasında tüm nesneleri dikkate alır.If object aging is not implemented, the garbage collector considers all objects during the garbage collection.

MaxGenerationParametresinin geçerli en büyük değerini öğrenmek için özelliğini kullanın generation .Use the MaxGeneration property to determine the maximum valid value of the generation parameter.

Atık toplayıcısının, nesilden bağımsız olarak tüm nesneleri kabul etmek için, bu yöntemin hiçbir parametre alan sürümünü kullanın.To have the garbage collector consider all objects regardless of their generation, use the version of this method that takes no parameters. Atık toplayıcısının nesneleri bir ayara göre geri kazanmak için GCCollectionMode GC.Collect(Int32, GCCollectionMode) yöntem aşırı yüklemesini kullanın.To have the garbage collector reclaim objects based on a GCCollectionMode setting, use the GC.Collect(Int32, GCCollectionMode) method overload.

Şunlara uygulanır

Collect(Int32, GCCollectionMode)

Bir atık toplamayı, bir değer tarafından belirtilen bir oluşturma yoluyla, belirli bir nesil 0 ' dan oluşturma işlemini zorlar GCCollectionMode .Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value.

public:
 static void Collect(int generation, GCCollectionMode mode);
public static void Collect (int generation, GCCollectionMode mode);
static member Collect : int * GCCollectionMode -> unit
Public Shared Sub Collect (generation As Integer, mode As GCCollectionMode)

Parametreler

generation
Int32

Atık olarak toplanabilecek en eski oluşturma sayısı.The number of the oldest generation to be garbage collected.

mode
GCCollectionMode

Çöp toplamanın zorla ( Default veya Forced ) veya optimize edilmiş () olduğunu belirten bir numaralandırma değeri Optimized .An enumeration value that specifies whether the garbage collection is forced (Default or Forced) or optimized (Optimized).

Özel durumlar

generation geçerli değil.generation is not valid.

-veya--or- mode değerlerden biri değil GCCollectionMode .mode is not one of the GCCollectionMode values.

Örnekler

Aşağıdaki örnek, bir atık toplamayı 2. nesil nesneler için ayarıyla zorlar Optimized .The following example forces a garbage collection for generation 2 objects with the Optimized setting.

using System;

class Program
{
    static void Main(string[] args)
    {
        GC.Collect(2, GCCollectionMode.Optimized);
    }
}
Class Program

    Public Shared Sub Main()
        GC.Collect(2, GCCollectionMode.Optimized)
    End Sub
End Class

Açıklamalar

modeÇöp toplamanın hemen mi yoksa yalnızca zaman nesneleri geri kazanmak için en iyi durumda mı gerçekleşeceğini belirtmek için parametresini kullanın.Use the mode parameter to specify whether garbage collection should occur immediately or only if the time is optimal to reclaim objects. Bu yöntemin kullanılması, belirtilen neslin tüm erişilemeyen belleğin geri kazanılabileceğini garanti etmez.Using this method does not guarantee that all inaccessible memory in the specified generation is reclaimed.

Uygulamanızda kritik dönemler sırasında çöp toplamanın zorlılık düzeyini ayarlamak için LatencyMode özelliği ayarlayın.To adjust the intrusiveness of garbage collection during critical periods in your application, set the LatencyMode property.

Atık toplayıcı, oluşturma numarası parametre tarafından belirtilenden daha yüksek olan nesneleri toplamaz generation .The garbage collector does not collect objects with a generation number higher than specified by the generation parameter. MaxGenerationGeçerli en büyük değerini öğrenmek için özelliğini kullanın generation .Use the MaxGeneration property to determine the maximum valid value of generation.

Atık toplayıcısının, nesilden bağımsız olarak tüm nesneleri kabul etmek için, bu yöntemin hiçbir parametre alan sürümünü kullanın.To have the garbage collector consider all objects regardless of their generation, use the version of this method that takes no parameters.

Atık toplayıcısının nesneleri belirtilen nesil nesnelere kadar geri kazanmak için, GC.Collect(Int32) yöntem aşırı yüklemesini kullanın.To have the garbage collector reclaim objects up to a specified generation of objects, use the GC.Collect(Int32) method overload. En yüksek üretimi belirttiğinizde tüm nesneler toplanır.When you specify the maximum generation, all objects are collected.

Şunlara uygulanır

Collect(Int32, GCCollectionMode, Boolean)

Bir atık toplamayı, bir değer tarafından belirtilen bir kez, belirtilen bir oluşturma aracılığıyla 0. kuşak ile, GCCollectionMode koleksiyonun engellenip engellenmeyeceğini belirten bir değerle zorlar.Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value, with a value specifying whether the collection should be blocking.

public:
 static void Collect(int generation, GCCollectionMode mode, bool blocking);
public static void Collect (int generation, GCCollectionMode mode, bool blocking);
static member Collect : int * GCCollectionMode * bool -> unit
Public Shared Sub Collect (generation As Integer, mode As GCCollectionMode, blocking As Boolean)

Parametreler

generation
Int32

Atık olarak toplanabilecek en eski oluşturma sayısı.The number of the oldest generation to be garbage collected.

mode
GCCollectionMode

Çöp toplamanın zorla ( Default veya Forced ) veya optimize edilmiş () olduğunu belirten bir numaralandırma değeri Optimized .An enumeration value that specifies whether the garbage collection is forced (Default or Forced) or optimized (Optimized).

blocking
Boolean

true engelleyici bir çöp toplama işlemi gerçekleştirmek için; false mümkün olduğunda bir arka plan atık toplama işlemi gerçekleştirmek için.true to perform a blocking garbage collection; false to perform a background garbage collection where possible.

Özel durumlar

generation geçerli değil.generation is not valid.

-veya--or- mode değerlerden biri değil GCCollectionMode .mode is not one of the GCCollectionMode values.

Açıklamalar

Aşağıdaki tablo mode ve parametrelerinin etkileşimini özetler blocking :The following table summarizes the interaction of the mode and blocking parameters:

mode blocking``trueblocking is true blocking``falseblocking is false
Forced veya DefaultForced or Default Engelleyici bir koleksiyon mümkün olan en kısa sürede gerçekleştirilir.A blocking collection is performed as soon as possible. Bir arka plan koleksiyonu devam ediyorsa ve generation 0 veya 1 ise, Collect(Int32, GCCollectionMode, Boolean) Yöntem bir engelleme koleksiyonunu hemen tetikler ve koleksiyon bittiğinde döndürür.If a background collection is in progress and generation is 0 or 1, the Collect(Int32, GCCollectionMode, Boolean) method immediately triggers a blocking collection and returns when the collection is finished. Bir arka plan koleksiyonu devam ediyorsa ve generation 2 ise, yöntem arka plan koleksiyonu tamamlanana kadar bekler, bir engelleme 2 toplamayı tetikler ve ardından döndürür.If a background collection is in progress and generation is 2, the method waits until the background collection is finished, triggers a blocking generation 2 collection, and then returns. Bir koleksiyon mümkün olan en kısa sürede gerçekleştirilir.A collection is performed as soon as possible. Collect(Int32, GCCollectionMode, Boolean)Yöntemi bir arka plan koleksiyonu ister, ancak bu garanti edilmez; koşullara bağlı olarak, bir engelleme koleksiyonu yine de gerçekleştirilebilir.The Collect(Int32, GCCollectionMode, Boolean) method requests a background collection, but this is not guaranteed; depending on the circumstances, a blocking collection may still be performed. Bir arka plan koleksiyonu zaten devam ediyorsa, yöntemi hemen döndürür.If a background collection is already in progress, the method returns immediately.
Optimized Çöp toplayıcı ve parametresinin durumuna bağlı olarak engelleme koleksiyonu gerçekleştirilebilir generation .A blocking collection may be performed, depending on the state of the garbage collector and the generation parameter. Çöp toplayıcı en iyi performansı sağlamaya çalışır.The garbage collector tries to provide optimal performance. Atık toplayıcısının durumuna bağlı olarak bir koleksiyon gerçekleştirilebilir.A collection may be performed, depending on the state of the garbage collector. Collect(Int32, GCCollectionMode, Boolean)Yöntemi bir arka plan koleksiyonu ister, ancak bu garanti edilmez; koşullara bağlı olarak, bir engelleme koleksiyonu yine de gerçekleştirilebilir.The Collect(Int32, GCCollectionMode, Boolean) method requests a background collection, but this is not guaranteed; depending on the circumstances, a blocking collection may still be performed. Çöp toplayıcı en iyi performansı sağlamaya çalışır.The garbage collector tries to provide optimal performance. Bir arka plan koleksiyonu zaten devam ediyorsa, yöntemi hemen döndürür.If a background collection is already in progress, the method returns immediately.

Yöntemine yapılan bir çağrı Collect(Int32, GCCollectionMode, Boolean) tam engelleme atık toplama işlemi gerçekleştiriyorsa, GCSettings.LargeObjectHeapCompactionMode GCLargeObjectHeapCompactionMode.CompactOnce yöntemi çağırmadan önce özelliğini olarak ayarlayarak büyük nesne yığınını da genişletebilirsiniz Collect .If a call to the Collect(Int32, GCCollectionMode, Boolean) method performs a full blocking garbage collection, you can also compact the large object heap by setting the GCSettings.LargeObjectHeapCompactionMode property to GCLargeObjectHeapCompactionMode.CompactOnce before calling the Collect method.

Şunlara uygulanır

Collect(Int32, GCCollectionMode, Boolean, Boolean)

Bir atık toplamayı, bir değer tarafından belirtilen bir kez, belirtilen bir oluşturma yoluyla, bir değerle belirtilen bir zamanda, GCCollectionMode koleksiyonun engellenip engellenmeyeceğini ve sıkıştırılmasını belirten değerlerle zorlar.Forces a garbage collection from generation 0 through a specified generation, at a time specified by a GCCollectionMode value, with values that specify whether the collection should be blocking and compacting.

public:
 static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting);
public static void Collect (int generation, GCCollectionMode mode, bool blocking, bool compacting);
static member Collect : int * GCCollectionMode * bool * bool -> unit
Public Shared Sub Collect (generation As Integer, mode As GCCollectionMode, blocking As Boolean, compacting As Boolean)

Parametreler

generation
Int32

Atık olarak toplanabilecek en eski oluşturma sayısı.The number of the oldest generation to be garbage collected.

mode
GCCollectionMode

Çöp toplamanın zorla ( Default veya Forced ) veya optimize edilmiş () olduğunu belirten bir numaralandırma değeri Optimized .An enumeration value that specifies whether the garbage collection is forced (Default or Forced) or optimized (Optimized).

blocking
Boolean

true engelleyici bir çöp toplama işlemi gerçekleştirmek için; false mümkün olduğunda bir arka plan atık toplama işlemi gerçekleştirmek için.true to perform a blocking garbage collection; false to perform a background garbage collection where possible.

compacting
Boolean

true küçük nesne yığınını sıkıştırmak için; false yalnızca tarama yapmak için.true to compact the small object heap; false to sweep only.

Açıklamalar

blockingİse false , GC bir arka plan veya engelleyici bir çöp toplama işlemi yapılıp yapılmayacağını belirler.If blocking is false, the GC decides whether to perform a background or a blocking garbage collection. compactingİse true , engelleyici bir çöp toplama işlemi gerçekleştirir.If compacting is true, it performs a blocking garbage collection.

compactingİse true , çalışma zamanı küçük nesne YıĞıNıNı (SoH) sıkıştırır.If compacting is true, the runtime compacts the small object heap (SOH). Özellik olarak ayarlanmadığı takdirde büyük nesne yığını (LOH) sıkıştırmaz GCSettings.LargeObjectHeapCompactionMode GCLargeObjectHeapCompactionMode.CompactOnce .The large object heap (LOH) is not compacted unless the GCSettings.LargeObjectHeapCompactionMode property is set to GCLargeObjectHeapCompactionMode.CompactOnce. Bunun yalnızca tam engelleme çöp koleksiyonları değil, tüm engelleyici çöp koleksiyonları içerdiğini unutmayın.Note that this includes all blocking garbage collections, not just full blocking garbage collections.

Collect(Int32, GCCollectionMode, Boolean, Boolean)Aşağıdaki kod parçasında gösterildiği gibi, yönetilen yığını mümkün olan en küçük boyuta düşürmek için yöntemini çağırabilirsiniz.You can call the Collect(Int32, GCCollectionMode, Boolean, Boolean) method to reduce the managed heap to the smallest size possible, as the following code fragment illustrates.

GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(2, GCCollectionMode.Forced, true, true);
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce
GC.Collect(2, GCCollectionMode.Forced, True, True)

true compacting Bağımsız değişken için belirtmek bir sıkıştırma, tam engelleme çöp toplamayı garanti eder.Specifying true for the compacting argument guarantees a compacting, full blocking garbage collection. Özelliği, GCSettings.LargeObjectHeapCompactionMode GCLargeObjectHeapCompactionMode.CompactOnce hem Loh hem de soh 'nin sıkıştırılmasını sağlamak için ayarlamak.Setting the GCSettings.LargeObjectHeapCompactionMode property to GCLargeObjectHeapCompactionMode.CompactOnce ensures that both the LOH and SOH are compacted.

Şunlara uygulanır