Re: larger data set size

Hi John,

> BTW, this message was just posted to one of the java mailists; i didnt
> know it and thought it useful info:
> "You can get an OutOfMemory error because you are trying to allocate
> more memory than the VM currently has available.  Of course, the VM is
> not smart enough to garbage collect and then try it again.  This is a
> very common thing that happens with large single allocations.  I use the
> following:
> try {
>     // huge allocation
> }catch( OutOfMemoryError e ){
>     Runtime.getRuntime().gc();
>     Runtime.getRuntime().runFinalization();
>     // try huge allocation again
> }
> If there really is enough memory, this will work.  We have a large
> imaging system we have written, and have this code peppered a lot of
> places."

I asked the SUN JRE group about this and got the following response
from a Sun engineer:

  Yes, this scenario can unfortunately occur with Classic VM. The HotSpot
  VM and the Solaris Production release VM does not have this problem, so
  for Java2 SE 1.3 ("JDK1.3") this will no longer be an issue since HotSpot
  will be the default VM.

  Classic VM has a "desired free percentage" after a full GC (parameter
  -Xminf, default 35% or so (-Xminf0.35). If this free percentage is not
  fulfilled after a full GC, a subsequent allocation failure will throw
  OutOfMemoryError. The workaround for Classic VM is to set -Xmx high
  enough or, alternatively, -Xminf low enough so that the amount of live 
  data always stays lower that the "desired free percentage" of the maximum 
  heap size.

  The following program shows the failure. This test throws OutOfMemoryError
  on Classic VM but runs fine with e.g. the HotSpot VM. If you set -Xmx
  higher or -Xminf lower the program also runs fine on Classic VM.

  // Run this with -Xms64m -Xmx64m
  public class Test {
    public static byte array1[] = null;
    public static byte array2[] = null;
    public static void main(String args[]) {
      array1 = new byte[48*1024*1024];
      while (true) {
        array2 = new byte[4*1024*1024];

So this is a bug in the JVM that is fixed in Hotspot and
JDK 1.3.

Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738