[Mono-list] Dispose() method in the UdpClient class

Jonathan Pryor jonpryor@vt.edu
Tue, 14 Oct 2003 19:38:46 -0400


The difference between managed and unmanaged resources?

Managed == Memory

Unmanaged == Everything Else.

:-)

It's perhaps not quite that clear cut, but it's close.  A managed
resource is a resource that the runtime (1) knows about, and (2) is
responsible for allocating and cleaning up.

That pretty much leaves memory.  File handles, Database connections, GUI
Windows...  Everything of interest will (eventually) be an unmanaged
resource.

Now, there are patterns to help integrate unmanaged resources with the
memory garbage collector (finalizers, the IDisposable interface), but
they're not a complete solution.  If you forget to Close/Dispose your
object, you'll leave the unmanaged resource open *at least* until the
next GC, which may be inappropriate.

(For one example of "inappropriate," database connections to commercial
databases are frequently limited to a small number -- due to licensing
issues -- so you don't want them open for long periods of time or you'll
kill performance.  Thus, you *must* ensure that the connection is
disposed as soon as possible, or face a mob of dissatisfied customers.)

 - Jon

On Tue, 2003-10-14 at 17:36, Met @ Uber wrote:
> On Tue, 2003-10-14 at 02:43, Gonzalo Paniagua Javier wrote:
> > El mar, 14-10-2003 a las 08:11, Giuseppe Greco escribió:
> > 
> > > 1. Isn't Socket a managed resource?
> > 
> > The Socket class holds a socket, that is an unmanaged resource. That's
> > why it's better to Close it explicitly instead of letting the GC do it.
> > 
> > -Gonzalo
> What's the difference between managed/unmanaged resources?  
> ...Just trying to learn.
> 
> ~ Matthew
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list