Re: " //Clean Up managed resources " f&*ck




Unmanaged code is such code that is not managed by the CLR.
Handles to files, windows etc. that obtained using unmanaged code
(e.g. by P/Invoke).

SqlConnection uses various of unmanaged code for it's implementation
of the underlying physical connection for example (socket connections,
named pipes etc..)
These kine of unmanaged resources are expensive so developers should
use the Dispose pattern to give the option of cleaning unmanaged
resources that are not in use in a deterministic way. Although it is
not necessary, it is very advisable to clean resources in a
deterministic way since GC is not deterministic.

Cheers,
Moty


If sql connection is managed resource
why dispose if called from finaliser in pattern above
should leave it untouched? I do not
understand! I was thinking that finaliser above
should guaraantee that dispose will be fired
if not called by hand by user of an object.

And if sql connection is unmanaged resource
what the hell is managed resource and how
it can be explicite free'd? :(

K

.



Relevant Pages

  • Re: Close() and Dispose()
    ... Dispose should close connection as well, but main purpose of Dispose not to ... close the connection but to release the resources for the unmanaged code ... situation when resources are not freed until you close your application. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Clean up resources
    ... dispose pattern = Dispose + Finalize must be used only with unmanaged code ... resources but the cannot be disposed and are managed directly by the GC: ... Managed code that implement IDisposable that containes managed classes ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Collecting communication events
    ... Notification broker works also from unmanaged code:) ... Every API that is managed, is also accessible from unmanaged code. ... Looking for some resources and info, ...
    (microsoft.public.pocketpc.developer)
  • Re: Closing a form
    ... > The articles you mentioned talk about operating on ... > unmanaged code. ... Forms are managed and the articles are dealing with managed code. ... Calling the Dispose() method explicitly is a good ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How can I make sure all unmanaged resources had been released ?
    ... SqlClient.SqlConnection should manually call Closeor Dispose() after ... SqlConnecont won't be closed when the connection object is out of range, ... > What type of unmanaged resources are you refering too? ... > Therefore if the unmanaged code is not desroying its objects, ...
    (microsoft.public.dotnet.languages.csharp)