Saturday, July 17, 2010

How to fix the OutOfMemoryError when writing tests with PowerMock - Part - 2

In my previous post we had a look at How to fix the OutOfMemoryError when writing tests with PowerMock

Looks like, the method I described in that post does not work on all machine or environments.

In one of the environment whose configuration is:
  • Windows 7 64 Bit
  • 4 GB RAM DDR3
  • Intel Core i7 processor
  • JDK 6 64 Bit  
  • PowerMock 1.3.7  
it seemed to work for some time, but as soon as we wrote a few more tests using PowerMock (Mockito api), the OutOfMemoryError re-appeared.

Now that's annoying, what the hell is wrong now!  Well as I said in the previous post memory leaks are hard to find and fix!

But we need a solution now!  Can't wait till PowerMock 1.4 version is released.  Hence, I was on a mission to fix the issue and get all my tests running by hook or crook!

In the process I found that, running the tests on a 32 bit machine had no problems what so ever!  Surprise, Surprise!

Investigated a little further, found that when tests are run on a machine with 64 bit OS but 32 bit JDK they all pass.  That was the moment of Truth!

These are the steps I followed to fix the OutOfMemoryError:
  • Installed the JDK 6 32 bit on my machine
  • Updated the JAVA_HOME environment variable
  • Added the JDK 6 32 bit bin directory to the PATH environment variable
  • Removed the earlier JDK 6 64 bit bin directory from the PATH environment variable.  
All set!  Ran all the test and bingo!  All pass its a SUCCESS!
Have some Fun!