Java server socket buffers are not garbage collected on Mac
I'm looking for a memory error in my application and it seems to be related to buffers [] buffers generated by ServerSocketChannel.accept (). According to jvisualvm, of the 505 megabytes used by the application, over 90% of the memory is used by byte [] arrays. Tracking it down further, there are 68k + instances of the [] byte, and the most common size is 16681.
I randomly sampled these byte arrays and they were all, without exception, associated with either InputRecord or OutputRecord. If I follow all the links, I can't find anything that doesn't lead to the Finalizer, which in my limited understanding means that the object is ready to be garbage collected, but it's not for some reason.
I wish I could bind the jvisualvm exit screen capture. In any case, the objects of the referent include:
- InputRecord
- AppInputStream
- SSLSocketImpl
- SocketInputStream
- SocksSocketImpl
- SocketOutputStream
- AppOutputStream
- DelegateHttpsURLConnection
- HttpsURLConnectionImpl
It looks like clients using Apple VM. Does anyone know why these buffers are not garbage collected? Am I reading the heap profile wrong? Hacks or Workarounds?
finalize
called some time after the object has been detected by the garbage collector. Sun's implementation is mixed with java.lang.ref
. Closing resources properly should free their memory. If the objects with finalize
do not delete references to buffers when they are closed, then those buffers will hang until the corresponding GC is executed after the finalizer is executed.
Typically there is only one finalizer, although the spec allows many. If it is blocked due to a lock operation, an inappropriate held lock, or some other reason, then the GC of the completed objects will be held. I suggest checking the finalizer stream in visualvm to see if it is blocked.
a source to share