Home » Java programming language

Explain OutOfMemory Error in java



Here, we are going to discuss about an error in java ‘OutOfMemory’, when and how it occurs, how to prevent this error?
Submitted by Preeti Jain, on February 10, 2018

OutOfMemory Error in java

  • OutOfMemoryError is a class of java.lang package.
  • JVM (Java Virtual Machine) is not able to allocate memory for an object because it is OutOfMemory JVM has its own memory that is very-2 limited and no more memory is available by garbage collector.
  • JVM (Java Virtual Machine) has its own memory capacity.
  • If you are not sure about that your programs space requires more than existing space then it is ran out of memory.

How can we analyze OutOfMemory Error? Here we will discuss some points:

  • Slow execution of program
  • Sudden Failure
  • Error found in the program console

We can resolve OutOfMemory Error in following ways,

  • Upgrade system Ram
  • You should know how much amount of memory you required for executing a particular task and try to reduce memory you are using.
  • If references are no longer required then we can release that memory by garbage collector and reuse them for other resources instead of re-allocating.
  • We should optimize code and by which we can reduce memory for a java program.

If we work with large object or working with large amount of data then OutOfMemory Error may occurs if memory is not enough to handle so much data.






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.