What if I don't set the Xmx flag?
Then the JVM defaults to a (typically modest) size of memory for the app.
Does it mean unlimited memory usage?
No.
How can I realize if the application is frozen in either C or Java?
Fix the memory leak1.
Note that the question I answered used 'release' as opposed to 'realize'. After careful consideration, I feel the answer should remain exactly the same. Either 'releasing (memory)' or 'realizing (there is a problem)' is not going to actually fix the problem. It is better either way to fix the actual problem (a memory leak).
As an aside. I don't think the problem is in the C code, but a simple test (launch the app. from the command line) should reveal either way. The reason I think the problem is the Java code is that the OutOfMemoryError
is detected by a (presumably) fully functional JVM.
If the C app. had used memory space that the JVM reserved for itself or the app. I guess the error would be very different, possibly along the lines of: JVM internal error..
1. Fixing the memory leak
There has been a range of good advice offered by other contributors, that I will revisit here.
- @ChristianKullmann started it off by stressing the importance of memory profiling.
- @KlasLindbäck followed it up with some excellent resources linked in a comment.
- Java Heap Dump.
"One way to find memory leaks is analyzing heap dumps. There are several ways to get a heap dump (not including 3rd party tools).." - Tips and tricks for analyzing Java virtual machine heap memory dumps.
"Memory dumps are a very useful feature of the JVM to analyze the contents of the memory at any given time, but their usage requires some experience, and in this post I will share with you some tips and tricks that I’ve learned over the years, so hopefully they will be useful to you too."
- Java Heap Dump.
- @mKorbel rounded it out with some typical problems to look for:
*"search in code if there areclose()
all:- JDBC,
- FileIO,
- Socket,
- etc and in finally block, then you'd love re_engeneering too much"*