Issue
My system has 8GB ram and my system is CentOS 7. The system info shows the following memory usage.
Memory Information
Total memory (RAM): 7.6 GB
Free memory: 143.4 MB (+ 6.1 GB Caches)
Free swap: 7.8 GB
Does this mean free memory is only 143.4MB, or 143.4 + 6.1BG? Why is it caches? Is this normal? I am asking this because I am running a Java problem but received an OutOfMemory exception. I am thinking whether there is any problem with my operating system.
Solution
It's more likely that you need to run your JVM with an increased maximum memory setting. The JVM will run with it's own limit on memory usage (subject to that available from the OS).
e.g.
$ java -Xmx2048m ...
will run the JVM with a maximum memory setting of 2Gb. See here for more information.
If you suffer from an OutOfMemoryException
, then it's likely that you need to tweak this setting. It is also possible that the JVM can't allocate that memory from the OS, or that your program suffers from a memory leak, but setting -Xmx
is a reasonable first approach to resolving such an issue. Note that setting -Xms
in a similar fashion will force the JVM to allocate the memory upon startup, and is useful not only as an optimisation, but also as an early warning for the lack of allocatbale memory. See here for more info.
Answered By - Brian Agnew Answer Checked By - Marilyn (WPSolving Volunteer)