Hi Cj,
Yes, normally, the resource in your description means unmanaged resource
encapsulated by the managed object. The unmanaged resource includes file
handle, bitmap resource, network/sql connections, window handle etc... .Net
GC can use the metadata to know how to collect the managed object space on
the heap, however, it knows nothing about the unmanaged resource, so the
designer of the class needs to implement the IDispose interface to tell the
developer to release the unmanaged resource.
Regarding SqlConnection, its unmanaged resource is the connection to the
SQL Server and this connection will normally be started by Open method. So
SqlConnection.Open method will allocate the unmanaged resource, and the
calling to Dispose and Close method is required to release it. However,
SqlConnection.ConnectionString is a managed string object, which is known
to GC. So it has nothing to do with Dispose/Close method. It will be freed
by .Net GC when there is not references from root to point to the
SqlConnection.
Hope this is clear.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
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.