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

Steinar Herland steinar.herland@gecko.no
Tue, 14 Oct 2003 09:19:14 +0200


>2. What the advantage of assigning socket to the s
>   local variable, and then call the Close() method
>   on it?
If you mean
---
    // release unmanaged resources
    if (socket !=3D null){
        socket.Close ();
        socket =3D null;
    }
}
--- Instead of ---
    // release unmanaged resources
    Socket s =3D socket;
    socket =3D null;
    if (s !=3D null)
        s.Close ();
}
---
One difference is that if an exception is thrown in the s.Close, then =
the socket (variable) is already set to null. This could be the reason, =
but I'm only guessing.


Steinar

-----Original Message-----
From: Gonzalo Paniagua Javier [mailto:gonzalo@ximian.com]
Sent: 14. oktober 2003 08:43
To: mono-list@lists.ximian.com
Subject: Re: [Mono-list] Dispose() method in the UdpClient class

El mar, 14-10-2003 a las 08:11, Giuseppe Greco escribi=F3:

> 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


_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com =
http://lists.ximian.com/mailman/listinfo/mono-list