Tekkaman

导航

 

GC类

  GC是一个静态类。

  

  垃圾回收器跟踪并回收托管内存中分配的对象。垃圾回收器定期执行垃圾回收以回收分配给没有有效引用的对象的内存。当使用可用内存不能满足内存请求时,垃圾回收会自动进行。或者,应用程序可以使用 Collect 方法强制进行垃圾回收。

  垃圾回收器不识别非托管代码中对对象的引用,因此,除非明确禁止,否则它有可能释放非托管代码中以独占方式使用的对象。KeepAlive 方法提供一种机制,该机制可防止垃圾回收器回收在非托管代码中仍使用的对象。

1、AddMemoryPressure & RemoveMemoryPressure。

    

  

  In determining when to schedule garbage collection, the runtime takes into account how much managed memory is allocated. If a small managed object allocates a large amount of unmanaged memory, the runtime takes into account only the managed memory, and thus underestimates the urgency of scheduling garbage collection. The AddMemoryPressure method informs the runtime of this additional pressure on system memory.

  In the simplest usage pattern, a managed object allocates unmanaged memory in the constructor and releases it in the Dispose or Finalize method. Call the AddMemoryPressure method after allocating the unmanaged memory, and call the RemoveMemoryPressure method after releasing it.

参考:http://msdn.microsoft.com/zh-cn/library/system.gc(v=vs.90).aspx

posted on 2014-07-20 11:44  Tekkaman  阅读(356)  评论(0编辑  收藏  举报