Tech Off Post

Single Post Permalink

View Thread: Involving Channel9 in .NET Framework Design Guidelines updates
  • User profile image
    John Melville-- MD

    Somewhere in the Docs I found a pattern that really works for me.

    class X: IDisposable {

        ~X() {Dispose();}

        public void Dispose() {
           // release all my resources
          GC.SuppressFinalize(this);    
        }

    }

    I think this provides the best of several worlds.  If I just want to ignore resources, everything will eventually, if nondeterministically, be cleaned up and it won't leak -- at the cost of every object living for an additional GC.  If resources or performance are an important issue, I can deal with explicit disposal.
     
         The GC provides a backup to disposal using this pattern so it doesn't matter if I miss a couple.  Often the difficuties in explicit disposal are infrequent corner cases.  It may be that even in a performance critical app explicitly disposing only of the 90% of the allocated objects will be enough.

    I agree that nonmemory resources have complicated disposal requirements that are difficult to model in general, so I do not think the generalized resource collector is necessary or possible.