开发者

dot net Memory Disposal, Is CLR garbage collector deals with other resources?

DOT NET garbage collector can only deals with memory resources or it also handles other resources u开发者_StackOverflow中文版sed by orphaned object?

How CLR deals to free these other resources used by orphaned object.


The GC only deals with managed objects.

All unmanaged resources need to be dealt with manually:

  1. Implement the IDisposable interface on any types that use unmanaged resources.
  2. Ensure that you call the Dispose method when you're done with using any objects that implement IDisposable. This is often done by using a using block.


The .Net GC manages only objects that are put up on managed heap, i.e. managed objects. These managed objects may inturn access unmanaged objects like DB connection or a file handle etc. The developer needs to free these resources by implementing IDisposable or Finalize, depending on your needs.

MSDN states that:

A type must implement Finalize when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed. See the IDisposable interface for a complementary and more controllable means of disposing resources.

Here's the link for the same: http://msdn.microsoft.com/en-us/library/system.object.finalize.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜