What will happen in a scenario when there is some error(like out of memory error) in a program and it exits abruptly , how will the memory allocated to the code handled in java.
Asked
Active
Viewed 67 times
0
-
4Wouldn't this be specific to how the OS reclaims memory? Is that what you're asking? – Keith Sep 30 '15 at 20:12
-
2Are you talking about what the JVM will do if a thread dies, or what the OS will do if the JVM dies, or something else? Can you give a more detailed scenario of what you're talking about? – azurefrog Sep 30 '15 at 20:16
-
I guess the above condition will be more specific to what @Keith has mentioned – dexterousashish Sep 30 '15 at 20:20
-
2To add to Keith's comment, it depends on the OS. Earlier version of Windows do not have the ability to defragment memory so you could start a JVM that uses a lot of memory with no problems and then during a later restart run into not enough memory errors despite the fact that you have enough free memory, but not enough continuous free memory. – EGHM Sep 30 '15 at 20:28
1 Answers
1
Generally speaking, you're asking about operating system memory management, which is agnostic to the process whose memory is deallocated (e.g. a JVM). When the JVM exits uncleanly, the OS will halt all of the JVM's threads. The pages of memory being used will be deallocated as well. When an operating system deallocates memory, that physical region is now able to be allocated by either the OS or another process.
If you are also curious as to whether the JVM can recover, there are a decent set of answers on StackOverflow to that specific question.