Yes, in general, the GC will usually close connections when the
corresponding files are collected. But a) you can't really rely on that and
b) the number of file descriptors that a program can open is very limited
and for many programs, the rate at which they are opened is high enough,
that they will pass that threshold, because the GC doesn't collect them
quickly enough.

Given how limited file descriptors are, you thus should still take care to
actually close all files you open yourself.

On Thu, Feb 16, 2017 at 9:29 AM, <caspia...@gmail.com> wrote:

> Thanks for you reply!
> Means yes, GC will close unused connection, just indirectly?  Cause I
> found this:
> #/opt/go/src/net/fd_unix.go
> func (fd *netFD) setAddr(laddr, raddr Addr) {
>         fd.laddr = laddr
>         fd.raddr = raddr
>         runtime.SetFinalizer(fd, (*netFD).Close)
> }
>
> And this function is called by netFD.dial in sock_posix.go:148
>
>
> 在 2017年2月16日星期四 UTC+8下午3:31:07,Jan Mercl写道:
>>
>> On Thu, Feb 16, 2017 at 8:20 AM <casp...@gmail.com> wrote:
>>
>> > Will GC close unused connection ?
>>
>> No. At least not directly. A finalizer can possibly do that and
>> finalizers are possibly invoked by the GC.
>>
>> --
>>
>> -j
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to