The java.lang.OutOfMemoryError error can also be thrown by native library code when a native allocation cannot be satisfied (for example, if swap space is low).

The detail message Java heap space indicates that an object could not be allocated in the Java heap. This error does not necessarily imply a memory leak. The problem can be as simple as a configuration issue, where the specified heap size (or the default size, if it is not specified) is insufficient for the application. 1

Heap memory is the run time data area from which the memory for all java class instances and arrays is allocated. The heap is created when the Java Virtual Machine starts up and may increase or decrease in size while the application runs. 2

These are heap size default selections: Initial heap size of 1/64 of physical memory; Maximum heap size of 1/4 of physical memory. 3

The minimum and maximum heap sizes that the garbage collector can use can be set using -Xms=<nnn> and -Xmx=<mmm> for minimum and maximum heap size respectively. 4

If the heap grows to its maximum size and the throughput goal isn’t being met, then the maximum heap size is too small for the throughput goal. Set the maximum heap size to a value that’s close to the total physical memory on the platform, but doesn’t cause swapping of the application. Execute the application again. If the throughput goal still isn’t met, then the goal for the application time is too high for the available memory on the platform. 5