mohit.chawla wrote:
Hi Mike,
Thank you for your reply, but another thing which has put me in confusion again is that the Connection class and the Command class also do not impliment the IDisposable and inherits from componentModel.Component.
But on call of the dispose method of any of them, Dispose does what it is supposed to do, i.e. it closes the connection and releses the connection.
So if dispose behaves this way for other classes then y not for datatable or a dataset.
Because they're coded that way.
Take a look at the documentation for
IDisposable; it's simply
"a method to to release umanaged resources"
There's no tight coupling with object disposal.
So the reason why datatable and datasets can still be accessed is probably because the parts you are accessing aren't unmanaged resources, so dispose does nothing to touch those bits.
(In fact if you fire up reflector and look at DataTable it only has a dispose method because it's ineriting from MarshalByRefComponent and does not implement its own Dispose method. The
documentation hints at this. So DataTable, and DataSet's dispose methods don't touch anything that is specific to those objects, hence the behaviour you're seeing.
Just remember that Dispose is detached from object finialisation/release, and can be called at any time.