Possible Duplicate:
Any sense to set obj = null(Nothing) in Dispose()?
I understand if this question is closed as a duplicate, but I'm having some trouble reconciling some posts on this topic.
First a little background. I have a class Foo as follows
public class Foo : IDisposable
{
private Dictionary<int, string> _reallyBigDictionary =
new Dictionary<int, string>();
public void Dispose()
{
_reallyBigDictionary = null;
}
}
Instances of Foo are known to have a limited scope (i.e. I know we're not keeping it around forever). Given it's instance's limited scope, I don't see how nulling out _reallyBigDictionary actually frees up memory sooner than the dispose. The way I understand it, these objects won't ever get cleaned up until garbage collection is run. At that time, references to the given instance of Foo will be null regardless, so I expect GC to reclaim that memory regardless.
These posts lead me to believe that there is no point in setting member variables to null:
Memory leak problems: dispose or not to dispose managed resources?
Is it better to destroy all objects or just let the garbage collector do the job?
This post makes me question otherwise: Proper use of the IDisposable interface
Can anyone clarify this point for me? Is the IDisposable implementation really necessary here? Because I just can't convince myself it is.