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.

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.