垃圾回收Garbage Collection

.NET 的垃圾回收器管理应用程序的内存分配和释放。.NET's garbage collector manages the allocation and release of memory for your application. 每当有对象新建时,公共语言运行时都会从托管堆为对象分配内存。Each time you create a new object, the common language runtime allocates memory for the object from the managed heap. 只要托管堆中有地址空间,运行时就会继续为新对象分配空间。As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. 不过,内存并不是无限的。However, memory is not infinite. 垃圾回收器最终必须执行垃圾回收来释放一些内存。Eventually the garbage collector must perform a collection in order to free some memory. 垃圾回收器的优化引擎会根据所执行的分配来确定执行回收的最佳时机。The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. 执行回收时,垃圾回收器会在托管堆中检查应用程序不再使用的对象,然后执行必要的操作来回收其内存。When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

TitleTitle 说明Description
垃圾回收的基础知识Fundamentals of Garbage Collection 描述垃圾回收的工作原理、如何在托管堆上分配对象,以及其他核心概念。Describes how garbage collection works, how objects are allocated on the managed heap, and other core concepts.
垃圾回收和性能Garbage Collection and Performance 介绍了可用来诊断垃圾回收和性能问题的性能检查。Describes the performance checks you can use to diagnose garbage collection and performance issues.
已引发回收Induced Collections 描述如何完成垃圾回收。Describes how to make a garbage collection occur.
延迟模式Latency Modes 描述确定垃圾回收侵入性的模式。Describes the modes that determine the intrusiveness of garbage collection.
针对共享 Web 托管进行优化Optimization for Shared Web Hosting 介绍了如何在多个小网站共用的服务器上优化垃圾回收。Describes how to optimize garbage collection on servers shared by several small Web sites.
垃圾回收通知Garbage Collection Notifications 介绍了如何确定全面垃圾回收的开始时间和结束时间。Describes how to determine when a full garbage collection is approaching and when it has completed.
应用程序域资源监视Application Domain Resource Monitoring 介绍了如何监视应用程序域的 CPU 和内存使用情况。Describes how to monitor CPU and memory usage by an application domain.
弱引用Weak References 描述允许应用程序访问对象的同时也允许垃圾回收器收集相应对象的功能。Describes features that permit the garbage collector to collect an object while still allowing the application to access that object.

参考Reference

System.GC

System.GCCollectionMode

System.GCNotificationStatus

System.Runtime.GCLatencyMode

System.Runtime.GCSettings

GCSettings.LargeObjectHeapCompactionMode

Object.Finalize

System.IDisposable

请参阅See also