This is a runtime error simply means that the JVM ran out of memory.
We can choose either of the below two solutions to fix it.
1) Prevent memory leak: Yes. Preventing memory leak will also improve the performance of the application. A memory leak can be very latent. A memory leak occurs when the application creates more references to objects and never releases them. So the garbage collector will never collect those objects results less free memory will be available, hence not enough free memory is available for the application to function normally.
2) Increase the heap size of the JVM.
It can be done by using the VM argument –Xmx
Syntax: java -Xmx<size> <java class> -d<bit mode>
Where, Size is the size of the memory asking JVM to take
Java class is the program name to which memory is required
Bit mode tells which bit mode of operating system is being used. Either 32 bit or 64 bit
Ex: java -Xmx1024m MyJavaClass -d32 //It asks JVM for 1024 MB space Java
java -Xmx2g MyJavaClass –d32 //It asks JVM for 2 GB space Java
Visit articles page of the website learningmela.com for more details.