Edit: My question isn\'t getting the main answer that I was looking for. I wasn\'t clear. I would really like to know two things:
For me:
Dispose
can be used in using() scope. This can help me to determine the lifespan of a IDisposeable
component. I usually use this in StreamWriter
/Reader or SqlConnection
classes.
Another use of Dispose
is it can end a lifespan of a component explicitly. Such as calling Form.Dispose()
in C# winform will close the form. However, for SqlConnection
, people said that just calling Dispose
alone without explicitly calling Close
won't guarantee the connection to be closed. Advised to call both Close
and Dispose
. I haven't tried this though.
And another thing, after Dispose()
is called, the GC can immediaetly free the memory, because they know that the object lifespan is end, rather than waiting for the lifespan to end.
Similiar question may be C# disposing IDisposable