Hi Brad,
In .NET world, it's the garbage collector's responsibility to release and
destroy an object. In fact, we have no way to destroy an object manully or
actively in .NET world at all. After an object leaves scope, it is ready
to be destroyed by the garbage collector.
All the DataReaders available in .NET Framework, i.e. SqlDataReader,
OleDataReader, OdbcDataReader and OracleDataReader are derived from the
DbDataReader class. The DbDataReader class has implemented the IDisposable
interface, which means when we don't need to use a DbDataReader object any
more, we should call the IDisposable.Dispose method on the DbDataReader
object to release the resources the object uses immediately.
After calling the Dispose method, we set the DbDataReader object to null or
Nothing to make the object out of scope.
For DataSet, it doesn't implement the IDisposable interface. When we don't
need a DataSet object, just set it to null or Nothing to make it out of
scope.
In your scenario, because you return a DataSet or DataReader in a function,
you couldn't call the Dispose method on the returned DataReader object or
set the DataSet or DataReader to null(Nothing) at the end of the function.
But you should call the Dispose method on the DataReader object and then
set the DataReader or DataSet object to null(Nothing) when you don't need
them outside of the function.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.