I do know about "Using", or so I thought. The reason why I questioned it
is
that FunctionA was able to bind
a data control to the dataset returned from FunctionB, even though
FunctionB used "Using".
I have a feeling the GC didn't collect the Dataset object until after
FunctionA
used it, a timing thing of sorts (?)
What do you think?
Um.
The first thing that comes to mind is that you seem to be
confusing disposal of objects with garbage collection. They aren't the
same thing.
Disposing an object tells that object to release any resources it deems
appropriate. This could be anything, but normally it would just be
unmanaged resources (e.g. operating system objects). But in no case would
calling Dispose() on an object affect whether that object itself could be
garbage collected. At best, it could affect other objects that object
references.
So, whether or not you call Dispose() on the DataSet object, the reference
to the DataSet object still exists, and can still be used to whatever
extent the DataSet class allows after being disposed. This could in fact
even include being bound to a control, and given that that seems to work
for you, it appears that DataSet is fine doing that, at least as you're
using the DataSet class there.
Personally, I wouldn't call Dispose() on an object I'm not done with. For
objects that support some kind of early disposal or releasing of
resources, they generally implement some other method to do that, such as
Close() for example. The Dispose() method, even if it's not explicitly
enforced by .NET, carries an implication that you're done with the
object. So don't call it unless you're actually done.
In any case, whether or not it's fine to do that, calling Dispose() on the
DataSet object wouldn't affect whether the object itself is collected by
the garbage collector.
Pete