it begins with me reading a stackoverflow answer
StringWriter
implments public abstract class TextWriter : MarshalByRefObject, IDisposable
on MSDN it says:
The Framework provides the System.IDisposable interface that should be implemented to provide the developer a manual way to release unmanaged resources as soon as they are not needed.
but what is considered as unmanaged resources? I clearly don't think StringWriter
qualifies. if I write my own without inheriting IDisposable....I don't see any need to add Dispose()
class ConfusedDevStringWriter{
private StringBuilder sb;
public ConfusedDevStringWriter(){ //ctor
sb = new StringBuilder();
}
}
And indeed I tested with visual studio memory debugger:
once the function returns,
StringWriter
and its StringBuilder
are freed...Moreoever, calling dispose seems to do nothing for StringWriter...
So not every class that inherit from IDisposable
has useful Dispose
. Again this goes back to my question what is considered as unmanaged resources (examples will be much appreciated n_n). I heard files are one of it...but isn't CLR a VM?...every resources should be managed by it, non?