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



On May 18, 11:24 pm, "Koliber (js)" <profesor_kinb...@xxxxxxxxxxxxxx>
wrote:
On 18 Maj, 21:03, "Nicholas Paldino [.NET/C# MVP]"<m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Koliber,

What this means is that if you the disposing parameter of the Dispose
method is true, then you want to call Dispose on any reference that you have
which implements IDisposable. Say your class had a SqlConnection that it
was holding onto. If the disposing parameter was true, then you would call
Dispose on the connection, otherwise, you would not.

No no no no
Net says to me that SqlConnection is unmanaged resource (resource I
should manage) - you say that
it is managed resource? If so what is unamanaged resource?

K.

K,

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

.



Relevant Pages

  • Re: Memory usage increace over time until program crashes.....
    ... but if the SqlConnection etc. are hanging around, how come the Memory usage fall from 200 MB down to 10 MB, when I minimize. ... Think I will just have to go though the code again and be sure I close all SqlConnection and Dispose them ... (the only resource you hold on to that implements IDisposable). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: " //Clean Up managed resources " f&*ck
    ... SqlConnection is a managed resource. ... What this means is that if you the disposing parameter of the Dispose ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: " //Clean Up managed resources " f&*ck
    ... What this means is that if you the disposing parameter of the Dispose ... Net says to me that SqlConnection is unmanaged resource (resource I ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: " //Clean Up managed resources " f&*ck
    ... Since Dispose ... methods is responsible for cleaning resources, the finalizer code ... it is about 'managed resource'. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: object.close() or object = null?
    ... Dispose method is called either explicitly or implicitly by creating the ... resources, and the reference count of a COM object is an unmanaged resource, ... Failure to dispose IDisposable objects typically doesn't lead to memory ...
    (microsoft.public.dotnet.languages.csharp)