IDisposable is one of the core programming tools against .Net memory leaks. Although the documentation suggests that it should be used for external resources, I widely use IDisposable to release internal resources, such as pointers to parent classes.
It is fairly easy to demonstrate this requirement by creating two mutually referenced classes, i.e. foo and bar. foo refers to a bar and vice versa. When foo falls out of scope, the GC sees that the bar is still referencing it, so it is not going to (and vice versa). No memory is collected.
This is the same problem style that EventHandlers invokes, where this link is not issued when the form is closed, if it is not explicitly released, or the WeakEvent model is not implemented.
I would suggest that the best practice is to use the C ++ programming model, in which you cleanse yourself after using Dispose if you are not sure if the GC can work for you.
source share