Ray's playground

 

Item 15: Utilize using and try/finally for Resource Cleanup(Effective C#)

  In some ways, resource management can be more difficult in C# than it was in C++. You can’t rely on deterministic finalization to clean up every resource you use. But a garbage-collected environment really is much simpler for you. The vast majority of the types you make use of do not implement IDisposable. Less than 100 classes in the .NET Framework implement IDisposable—that’s out of more than 1,500 types. When you use the ones that do implement IDisposable, remember to dispose of them in all cases. You should wrap those objects in using clauses or try/finally blocks. Whichever you use, make sure that objects get disposed properly all the time, every time.

posted on 2011-01-24 21:52  Ray Z  阅读(164)  评论(0编辑  收藏  举报

导航