jeudi 14 juillet 2016

If Java is a managed language then why do we have to manually close AutoCloseable resources? [duplicate]

This question already has an answer here:

In java, is it necessary for me to manually close all AutoCloseable and Closeable objects (whether through explicit call or relying on try-with-resources)?

Does the JVM not automatically clean up AutoCloseables and Closeables when they are no longer being referenced?

Is calling close explicitly (whether through explicit call or relying on try-with-resources) a manner of etiquette (i.e., recommended but not necessary) and is the reason to avoid indeterministic resource deallocation which would happen otherwise if one relied on the built in GC?

Aucun commentaire:

Enregistrer un commentaire