On Dispose

Wallym has some href="http://dotnetweblogs.com/wallym/posts/4987.aspx"> good thoughts on the
importance of calling dispose, which reminded me we have a complete whitepaper
on how to implement dispose correctly… Love to have your feedback on it.

paper on Dispose


Comments (2)

  1. Anonymous says:

    Section 3.1 implies that you do not have to call Dispose on managed containers which contain references to unmanaged resources, if I read it correctly:

    "This variation applies to types that hold references to only other managed objects that do not implement IDisposable and do not have Finalizers. This includes ensuring that no internal container, for example ArrayList, stores objects that require explicit resource cleanup. In such case, you don’t need to do anything special in terms of resource management."

    However, in this case, if you didn’t dispose the objects in the container manually, how would Dispose ever be called on them until they manually undergo a garbage collection?

  2. Krzysztof Cwalina says:

    The paragraph clearly states that the referenced (contained) objects cannot be Disposable for the container to be a Simple Type (not Disposable). The second sentence, now that I read it, may be not very clear but it’s meant to say that if one of the referenced objects is a collection, the items in the collection cannot be Disposable either.