Skip to main content

java.lang.OutOfMemoryError


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.

Popular posts from this blog

Fun Facts

Do you want to improve your knowledge? Do you want to impress friends with some facts? Then Fun Facts app is for you. "Fun Facts" is an android app shows some quotes which are funny but real facts. Install the app @  https://play.google.com/store/apps/details?id=com.sonuappz.funfacts

Java program to create PDF files

The below is a program to create a PDF text file in Java language.   This program reads a line of text from user and the text will be written to a pdf file. The pdf file name also be taken from the user input. This is a console java program.   Click here   to know more about the project.    Visit  Projects  page of  learningmela.com  to download more projects.

Java Program to use LDAP server

The below is a java program to demonstrate how to use the LDAP server connection to validate a user authentication. To check the authentication using LDAP server we required the user id and its password. We need to create a context to the LDAP server before connecting to it. And also we required to know the field names in the LDAP server.   Click here   to know more about the project.    Visit  Projects  page of  learningmela.com  to download more projects.