GC 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
사용되지 않는 메모리를 자동으로 회수하는 서비스인 시스템 가비지 수집기를 제어합니다.
public ref class GC abstract sealed
public ref class GC sealed
public static class GC
public sealed class GC
type GC = class
Public Class GC
Public NotInheritable Class GC
- 상속
-
GC
예제
다음 예제에서는 여러 GC 메서드를 사용하여 사용되지 않는 개체 블록에 대한 생성 및 메모리 정보를 가져와 콘솔에 출력합니다. 그런 다음 사용되지 않는 개체가 수집되고 결과 메모리 합계가 표시됩니다.
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}"
0
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
설명
이 API에 대한 자세한 내용은 GC에 대한 추가 API 비고를 참조하세요.
속성
| Name | Description |
|---|---|
| MaxGeneration |
시스템에서 현재 지원하는 최대 세대 수를 가져옵니다. |
메서드
| Name | Description |
|---|---|
| AddMemoryPressure(Int64) |
가비지 수집을 예약할 때 고려해야 하는 관리되지 않는 메모리의 대용량 할당을 런타임에 알립니다. |
| AllocateArray<T>(Int32, Boolean) |
배열을 할당합니다. |
| AllocateUninitializedArray<T>(Int32, Boolean) |
가능한 경우 0 초기화를 건너뛰는 동안 배열을 할당합니다. |
| CancelFullGCNotification() |
가비지 수집 알림의 등록을 취소합니다. |
| Collect() |
모든 세대의 즉시 가비지 수집을 강제합니다. |
| Collect(Int32, GCCollectionMode, Boolean, Boolean) |
컬렉션이 차단 및 압축되어야 하는지 여부를 지정하는 값을 사용하여 값으로 GCCollectionMode 지정된 시간에 0세대부터 지정된 세대까지 가비지 수집을 강제로 수행합니다. |
| Collect(Int32, GCCollectionMode, Boolean) |
가비지 수집을 0세대부터 지정된 세대까지 값으로 GCCollectionMode 지정된 시간에 컬렉션 차단 여부를 지정하는 값으로 강제합니다. |
| Collect(Int32, GCCollectionMode) |
값으로 지정된 시간에 0세대부터 지정된 세대까지 가비지 수집을 GCCollectionMode 강제로 수행합니다. |
| Collect(Int32) |
0세대부터 지정된 세대까지 즉시 가비지 수집을 수행합니다. |
| CollectionCount(Int32) |
지정된 개체 생성에 대해 가비지 수집이 발생한 횟수를 반환합니다. |
| EndNoGCRegion() |
GC 지역 대기 시간 모드를 종료하지 않습니다. |
| GetAllocatedBytesForCurrentThread() |
수명이 시작된 이후 현재 스레드에 할당된 총 바이트 수를 가져옵니다. |
| GetConfigurationVariables() |
가비지 수집기에서 사용하는 구성을 가져옵니다. |
| GetGCMemoryInfo() |
가비지 수집 메모리 정보를 가져옵니다. |
| GetGCMemoryInfo(GCKind) |
가비지 수집 메모리 정보를 가져옵니다. |
| GetGeneration(Object) |
지정된 개체의 현재 생성 번호를 반환합니다. |
| GetGeneration(WeakReference) |
지정된 약한 참조 대상의 현재 생성 번호를 반환합니다. |
| GetTotalAllocatedBytes(Boolean) |
프로세스의 수명 동안 할당된 바이트 수를 가져옵니다. 반환된 값에는 네이티브 할당이 포함되지 않습니다. |
| GetTotalMemory(Boolean) |
조각화를 제외한 힙 크기를 검색합니다. 예를 들어 총 GC 힙 크기가 100mb이고 조각화가 사용 가능한 개체에서 차지하는 공간이 40mb를 차지하는 경우 이 API는 60mb를 보고합니다. 매개 변수는 시스템에서 가비지 수집 및 개체 완료를 허용하기 위해 반환하기 전에 짧은 간격을 기다릴 수 있는지 여부를 나타냅니다. |
| GetTotalPauseDuration() |
프로세스 시작 이후 GC에서 일시 중지된 총 시간을 가져옵니다. |
| KeepAlive(Object) |
지정된 개체를 참조하여 현재 루틴의 시작부터 이 메서드가 호출되는 지점까지 가비지 수집에 부적격합니다. |
| RefreshMemoryLimit() |
가비지 수집기에서 시스템의 다양한 메모리 제한을 검색하여 다시 구성하도록 지시합니다. |
| RegisterForFullGCNotification(Int32, Int32) |
조건이 전체 가비지 수집을 선호하는 경우와 수집이 완료된 경우 가비지 수집 알림을 발생시켜야 하며, |
| RegisterNoGCRegionCallback(Int64, Action) |
특정 양의 메모리가 GC 없음 지역에 할당될 때 호출할 콜백을 등록합니다. |
| RemoveMemoryPressure(Int64) |
관리되지 않는 메모리가 해제되었으며 가비지 수집을 예약할 때 더 이상 고려할 필요가 없음을 런타임에 알릴 수 있습니다. |
| ReRegisterForFinalize(Object) |
시스템이 이전에 호출된 지정된 개체의 종료자를 호출하도록 요청합니다 SuppressFinalize(Object) . |
| SuppressFinalize(Object) |
공용 언어 런타임이 지정된 개체의 종료자를 호출하지 않도록 요청합니다. |
| TryStartNoGCRegion(Int64, Boolean) |
지정된 양의 메모리를 사용할 수 있는 경우 중요한 경로를 실행하는 동안 가비지 수집을 허용하지 않으며, 가비지 수집기가 처음에 사용 가능한 메모리가 충분하지 않은 경우 가비지 수집기가 전체 차단 가비지 수집을 수행하는지 여부를 제어합니다. |
| TryStartNoGCRegion(Int64, Int64, Boolean) |
큰 개체 힙 및 작은 개체 힙에 대해 지정된 양의 메모리를 사용할 수 있는 경우 중요한 경로를 실행하는 동안 가비지 수집을 허용하지 않도록 시도하고, 처음에 사용 가능한 메모리가 충분하지 않은 경우 가비지 수집기가 전체 차단 가비지 수집을 수행하는지 여부를 제어합니다. |
| TryStartNoGCRegion(Int64, Int64) |
큰 개체 힙과 작은 개체 힙에 대해 지정된 양의 메모리를 사용할 수 있는 경우 중요한 경로를 실행하는 동안 가비지 수집을 허용하지 않습니다. |
| TryStartNoGCRegion(Int64) |
지정된 양의 메모리를 사용할 수 있는 경우 중요한 경로를 실행하는 동안 가비지 수집을 허용하지 않습니다. |
| WaitForFullGCApproach() |
공용 언어 런타임에 의한 전체 차단 가비지 수집이 임박했는지 여부를 확인하기 위해 등록된 알림의 상태를 반환합니다. |
| WaitForFullGCApproach(Int32) |
지정된 시간 제한 기간에 공용 언어 런타임에 의한 전체 차단 가비지 수집이 임박했는지 여부를 확인하기 위한 등록된 알림의 상태를 반환합니다. |
| WaitForFullGCApproach(TimeSpan) |
지정된 시간 제한 기간에 공용 언어 런타임에 의한 전체 차단 가비지 수집이 임박했는지 여부를 확인하기 위한 등록된 알림의 상태를 반환합니다. |
| WaitForFullGCComplete() |
공용 언어 런타임에 의한 전체 차단 가비지 수집이 완료되었는지 여부를 확인하기 위해 등록된 알림의 상태를 반환합니다. |
| WaitForFullGCComplete(Int32) |
런타임이 완료된 공용 언어로 가비지 수집을 차단하는 전체인지 여부를 확인하기 위해 등록된 알림의 상태를 지정된 시간 제한 기간에 반환합니다. |
| WaitForFullGCComplete(TimeSpan) |
차단 가비지 수집이 완료되었는지 여부에 대한 등록된 알림의 상태를 반환합니다. 전체 컬렉션에 대해 무기한 대기할 수 있습니다. |
| WaitForPendingFinalizers() |
종료자의 큐를 처리하는 스레드가 해당 큐를 비울 때까지 현재 스레드를 일시 중단합니다. |