Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
OutOfMemory error in java.awt.image.DataBufferInt.<init>

843807
Member Posts: 46,582
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
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
Comments
-
From [Primitive Data Types|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html]int: The int data type is a *32-bit* signed two's complement integer.
-
Thanks, Andrew.
But the maximum value of the int data type is 2,147,483,647. The value that I passed in the int array size is only 90,189,840.
new int[size] -- size is 90,189,840
I assumed that one element in the int array is 1 byte. Thus, it tries to allocate about 90,189,840 bytes or ~86MB.
Thanks. -
rei_xanther wrote:That is the maximum positive integer value that can be stored in (the 4 bytes of) a signed int, but..
..But the maximum value of the int data type is 2,147,483,647...The value that I passed in the int array size is only 90,189,840...its only connection with RAM is that each int requires 4 bytes of memory to hold it.new int[size] -- size is 90,189,840Sure. So the number of bytes required to hold those 90,189,840 ints is 360,759,360.I assumed that one element in the int array is 1 byte. ..Your assumption is wrong. How could it be possible to store 32 bits (4 bytes) in 8 bits (1 byte)? (a)
a) Short of some clever compression algorithm applied to the data. -
Thanks Andrew for the information.
I increased the java heap size (-Xmx) to 512M and javaplugin.maxHeapSize to 512M.
Using the same data, I still encounter OutOfMemory error.
Same logs I provided, the difference is the display of the heap space used:
max heap: 508
javaplugin.maxHeapSize: 512M
Thanks. -
We are able to resolve the issue by calling System.gc() manually before processing the Print Preview.
But as far as I know, it is not recommended to call System.gc() in the codes.
Thanks. -
It seems that there are times JVM does not perform garbage collection, that's why there are some instances wherein the OutOfMemory error are replicated.
Kindly advise. Thanks.
This discussion has been closed.