These resources are really closed during a regular JVM exit. However, you canβt always find out how you call your method, and you could call it 2,000 times outwardly another programmer, and these resources will begin to add up.
In addition, some non-mainstream operating systems may run into a problem: if the JVM was supposed to stop abnormally (via System.halt
or crash), then the resources may remain open (due to non-working cleaning code), potentially unusable until it reboots or will be released manually. Even on major systems, sockets can remain open for several minutes.
source share