简体   繁体   English

收集了Java 6套接字垃圾

[英]Java 6 Socket Garbage Collected

Quick question: 快速提问:

If a Socket object (and its locally cached InputStream and OutputStream objects) falls out of scope and is garbage collected, does the connection remain open in the JVM? 如果Socket对象(及其本地缓存的InputStream和OutputStream对象)超出范围并被垃圾回收,那么该连接是否在JVM中保持打开状态? (Ie, no EOFException would be thrown on the listening server) (即,不会在侦听服务器上引发EOFException)

No, a finalizer (of some object related to the socket) will end up closing the socket... at least in any sane implementation, IMO, just like any other non-memory resource (file handles etc). 不,终结器(与套接字相关的某些对象)最终将关闭套接字……至少在任何合理的实现方式IMO中,就像任何其他非内存资源(文件句柄等)一样。 This will happen at the whim of the garbage collector's timing though - I would treat this as a programming error, effectively. 不过,这将在垃圾收集器的时机发生时发生-我将其有效地视为编程错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM