Resources freed on JVM Exit?
When I exit the JVM due to a RunTimeException thrown part way thru
constructing an object that has acquired some resources (like inputStreams for instance), do the resources get closed/cleaned up by the JVM during it's exit or have I left these resources tied up permanently?
I'm very clear that I must cleanup the resources myself if dealing with checked Exceptions that I don't translate into a JVM exit.
Thanks in advance for any help.
[467 byte] By [
Maxiia] at [2007-11-26 18:36:09]

All the resources--memory, file handles, etc.--will be returned to the OS, BUT it's not guaranteed that streams will be flushed or other application-specfic cleanup done if you exit in an ugly manner.
Thanks for the replys. I'm getting out of this that a RunTimeException
caused exit of the JVM does not gaurantee cleanup of stream resources
in particular. Correct?
wrt finally, it is my understanding this execution gaurantee applies only to checked exceptions and not to RTEs? Is this correct?
Thanks,
> Thanks for the replys. I'm getting out of this that
> a RunTimeException
> caused exit of the JVM does not gaurantee cleanup of
> stream resources
> in particular. Correct?
Depends what you mean by cleanup. All the resources obtained from the OS will be returned. There's no guarantee any streams will be flushed though.
> wrt finally, it is my understanding this execution
> gaurantee applies only to checked exceptions and not
> to RTEs? Is this correct?
You could test your assumption very easily and see for yourself, but no, that's not correct.
Finally will always be executed unless the thread terminates--e.g. by System.exit, an untrapped signal, etc. Break, continue, throw, return in try or catch all transfer control to finally.