6 Replies Latest reply: Jul 22, 2010 10:43 PM by 843807 RSS

    OutOfMemory error in java.awt.image.DataBufferInt.<init>

    843807
      We have an applet application that performs Print Preview of the images in the canvas. The images are like a network of entities (it has pictures of the entities involve (let's say Person) and how it links to other entities). We are using IE to launch the applet.

      We set min heap space to 128MB, JVM max heap space to 256MB, java plugin max heap space to 256MB using the Control Panel > Java.

      When the canvas width is about 54860 and height is 1644 and perform Print Preview, it thows an OutOfMemoryError in java.awt.image.DataBufferInt.<int>, hence, the Print Preview page is not shown. The complete stack trace (and logs) is as follows:
      Width: 54860 H: 1644
      Max heap: 254 # using Runtime.getRuntime().maxMemory()
      javaplugin.maxHeapSize: 256M # using System.getProperties("javaplugin.maxHeapSize")
      n page x n page : 1x1
      Exception in thread "AWT-EventQueue-2" java.lang.OutOfMemoryError: Java heap space
           at java.awt.image.DataBufferInt.<init>(Unknown Source)
           at java.awt.image.Raster.createPackedRaster(Unknown Source)
           at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
           at java.awt.image.BufferedImage.<init>(Unknown Source)
           at com.azeus.gdi.chart.GDIChart.preparePreview(GDIChart.java:731)
           at com.azeus.gdi.chart.GDIChart.getPreview(GDIChart.java:893)
           at com.azeus.gdi.ui.GDIUserInterface.printPreviewOp(GDIUserInterface.java:1526)
           at com.azeus.gdi.ui.GDIUserInterface$21.actionPerformed(GDIUserInterface.java:1438)
           at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
           at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
           at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
           at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
           at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
           at java.awt.Component.processMouseEvent(Unknown Source)
           at javax.swing.JComponent.processMouseEvent(Unknown Source)
           at java.awt.Component.processEvent(Unknown Source)
           at java.awt.Container.processEvent(Unknown Source)
           at java.awt.Component.dispatchEventImpl(Unknown Source)
           at java.awt.Container.dispatchEventImpl(Unknown Source)
           at java.awt.Component.dispatchEvent(Unknown Source)
           at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
           at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
           at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
           at java.awt.Container.dispatchEventImpl(Unknown Source)
           at java.awt.Component.dispatchEvent(Unknown Source)
           at java.awt.EventQueue.dispatchEvent(Unknown Source)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
           at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
           at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
           at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
           at java.awt.EventDispatchThread.run(Unknown Source)

      Drilling down the cause of the problem. The OutOfMemory occurred in the constructor of DataBufferInt when it tried to create an int array:
      public DataBufferInt(int size) {
      super(STABLE, TYPE_INT, size);
      data = new int[size]; # this part produce out of memory error when size = width X height
      bankdata = new int[1][];
      bankdata[0] = data;
      }

      The OutOfMemory error occurred when size is width * height (54860 X 1644) which is 90,189,840 bytes (~86MB).

      I can replicate the OutOfMemory error when initiating an int array using a test class when it uses the default max heap space but if I increase the heap space to 256MB, it cannot be replicated in the test class.

      Using a smaller width and height with product not exceeding 64MB, the applet can perform Print Preview successfully.

      Given this, I think the java applet is not using the value assigned in javaplugin.maxHeapSize to set the max heap space, hence, it still uses the default max heap size and throws OutOfMemory in int array when size exceeds the default max heap space which is 64MB.

      For additional information, below is some of the java properties (when press S in java applet console):
      browser = sun.plugin
      browser.vendor = Sun Microsystems, Inc.
      browser.version = 1.1
      java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
      java.awt.printerjob = sun.awt.windows.WPrinterJob
      java.class.path = C:\PROGRA~1\Java\jre6\classes
      java.class.version = 50.0
      java.class.version.applet = true
      java.runtime.name = Java(TM) SE Runtime Environment
      java.runtime.version = 1.6.0_17-b04
      java.specification.version = 1.6
      java.vendor.applet = true
      java.version = 1.6.0_17
      java.version.applet = true
      javaplugin.maxHeapSpace = 256M
      javaplugin.nodotversion = 160_17
      javaplugin.version = 1.6.0_17
      javaplugin.vm.options = -Xms128M -Djavaplugin.maxHeapSpace=256M -Xmx256m -Xms128M
      javawebstart.version = javaws-1.6.0_17

      Kindly advise if this is a bug in JRE or wrong setting. If wrong setting, please advise on the proper way to set the heap space to prevent OutOfMemory in initializing int array.

      Thanks a lot.

      Edited by: rei_xanther on Jun 28, 2010 12:01 AM

      Edited by: rei_xanther on Jun 28, 2010 12:37 AM