Hi Sahil,
Miha,
What prevents me from releasing managed resources in dispose() ?
Nothing actually. But why would they (you mean references held by
dataset?) be released (you mean setting references to null/nothing?) in
Dispose?
It is enough if you set variable with reference to dataset to
null/nothing and everything will go away - no sooner or later then if you
explicitly release them (any reference that dataset holds) in dispose.
And really what is managed .. is a SqlConnection object managed?
Yes, it is managed but it holds unmanaged resources thus should it be
treated as an unmanaged resource in this context.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group
www.codezone-si.info
- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Sahil,
I don't think you are right here.
Dispose is primarly meant to free unmanaged resources and doesn't do
much on managed resources.
It normally doesn't matter whether you call or don't call Dispose on a
instance that doesn't use unamanged resources - from the GC point of
view.
However, since DataSet implementes (or better inherits) IDisposable and
you never know of future changes it is better to call it.
But for now, one really doesn't need to call Dispose on DataSet (note
that you actually should call it since it might act differently in a
future upgrade).
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group
www.codezone-si.info
Alvin,
This is really a question for the folks who architected the dataset
but here are my thoughts -
You *should* *must* dispose DataSets. Why? Because if you don't
Dispose the dataset, then when the Garbage Collector runs and the
DataSet is unreachable, instead of freeing the memory the DataSet is
using the Collector will add the DataSet to the FReachable queue and
promote it to a higher generation. And a dataset might occupy
considerable memory.
So why supress a finalizer?
Because it doesn't do anything in Datasets. (Or anything that inherits
from MarshalByValueComponent). Finalize in that class simply calls
dispose(false) --- completely useless, so might as well supress it.
Why such an implementation?
Because Disposing a dataset, should not dispose underlying datatables
(hey someone else might be using them). This logic is controlled
inside the dispose(true) stuff.
So what happens when you forget to call Dispose on a dataset?
Well I guess it sticks around in memory until the GC gets to it. Given
that it is a complex object, the entire object tree must be clean -
and that might take a while, so go ahead and dispose
datasets/datatables/data*.* whenever ur done using them.
- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
"Alvin Bruney [ASP.NET MVP]" <
www.lulu.com/owc> wrote in message
Does any body know or have a clue why the constructor of DataSet
needs GC.SuppressFinalize(this) call
--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at
www.lulu.com/owc
_________________________