Java OutOfMemory Error

We all would faced the OutOfMemory error some times in our projects. Some times it make some confusion to us that
we all thought  in college that Java manage it memory its own. Still there are some parameters by which you can tweak
you memory.
There are three basic reason which causes the OutOfMemory

  • Heap size
  • PermGen Space
  • Threads

Heap Size

Java always defines default heap size, it also varies with different version of jvm

java 1.5 has default 2mb minimum and 64 mb max heap size.

It always good to define your own heap size based on your application, other wise  GC overhead limit would exceed and throw the OutofMemory error

There can have some of following reasons and solution

  • Requested array size exceeds VM limit
  • Heap too small
  • Excessive use of finalizes
  • Monitor objects pending finalization
  • look for logic error in array allocation code
  • Memory leak

To avoid above error you should

  • Adjust maximum heap size (-Xms<size>)
  • Analyze heap dump(MemoryMXBean, jmap, jconsole)

I would be covering remaining topics in coming days.

Java bug

I am Java professional, working on Enterprise Java from last 8 years.

More Posts - Website

Follow Me:
TwitterLinkedIn