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]
# 1
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.
jverda at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 2
If you want to insure resources get cleaned up use a finally block.try {} catch {} finally {}
cmangiaa at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 3
> If you want to insure resources get cleaned up use a> finally block.> > try {> } catch {> > } finally {> > }A finally block will not be executed on e.g. System.exitKaj
kajbja at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 4
> If you want to insure resources get cleaned up use a> finally block.I think the OP is handling these situations correctly but was asking about what happens during abnormal JVM exits.
zadoka at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 5

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,

Maxiia at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 6

> 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.

jverda at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...
# 7
Thanks for the definitive clarification. Didn't know that throw also transfers control to finally.
Maxiia at 2007-7-9 6:10:12 > top of Java-index,Java Essentials,New To Java...