• Home »
  • »
  • Java.lang.OutOfMemoryError: Java heap space

Java.lang.OutOfMemoryError: Java heap space

Earlier today I was working on some packages for Backtrack 5 and I ran into this java error. I was attempting to run a new reporting tool called Magic Tree which is a java application, but every time I opened it, it would crash with the following error.


  1. root@bt:~/Tools# java -jar MagicTree-1487.jar
  2. JarClassLoader: Warning: Null manifest from input stream associated with: lib/MagicTree/XMLWriter.pm
  3. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  4.         at java.util.Arrays.copyOf(Arrays.java:2786)
  5.         at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
  6.         at com.simontuffs.onejar.JarClassLoader.copy(JarClassLoader.java:1216)
  7.         at com.simontuffs.onejar.JarClassLoader.loadBytes(JarClassLoader.java:580)
  8.         at com.simontuffs.onejar.JarClassLoader.loadByteCode(JarClassLoader.java:542)
  9.         at com.simontuffs.onejar.JarClassLoader.load(JarClassLoader.java:452)
  10.         at com.simontuffs.onejar.JarClassLoader.load(JarClassLoader.java:338)
  11.         at com.simontuffs.onejar.Boot.run(Boot.java:322)
  12.         at com.simontuffs.onejar.Boot.main(Boot.java:166)

At first I was pretty sure that I was missing the perl module XMLWriter but even after installing that I still had the error. Just in case you are installing this on a regular Ubuntu distro you will need:


  1. root@bt:~/Tools# apt-get install libxml-writer-perl

So even after installing this I still had the same error so I dug a little deeper and it seems my Java install was running out of memory. This was kind of odd because the install of Backtrack I am using has 3 gigs of memory. I did some searching and figured out how to pass Java some new memory parameters on the command line.


  1. java -Xms<initial heap size> -Xmx<maximum heap size>

Next I tried some new parameters:


  1. root@bt:~/Tools# java -Xms128m -Xmx512m -jar MagicTree-1487.jar

Increasing the memory in this way allowed magic tree to open and function properly. It does seem I am having some Jave memory leak issues but for now this is a quick and dirty fix to the problem.

Building Java Programs: A Back to Basics Approach (2nd Edition) (Paperback)

List Price: $121.60
New From: $61.60 USD In Stock
Used from: $9.63 USD In Stock

Sams Teach Yourself Java in 24 Hours (5th Edition) (Paperback)

List Price: $39.99 USD
New From: $4.50 USD In Stock
Used from: $0.01 USD In Stock