If jvm gc is a private socket instance, what happens to the underlying tcp connection?

If there is an unused socket instance but it is not closed.

Should jvm be gc this?

If so, will the tcp connection be automatically closed?

+3


source to share


1 answer


Garbage collection will invoke finalize()

, which in turn closes the connection.

See java.net.AbstractPlainSocketImpl

:



   protected void finalize() throws IOException {
        close();
    }

      

Almost like magic.

+5


source







All Articles