tags:

views:

252

answers:

6

We are cbse 12th grade ip students.. we are facing this exception and we do not know how to rectify this exception.

run:
Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
        at java.awt.image.Raster.createPackedRaster(Raster.java:458)
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
        at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:230)
        at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:484)
        at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
        at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:97)
        at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
        at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:119)
        at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
        at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
        at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
        at java.awt.image.Raster.createPackedRaster(Raster.java:458)
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
        at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:225)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:252)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:108)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:72)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:82)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:93)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:604)
        at java.awt.Component.createVolatileImage(Component.java:3316)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:4038)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3983)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4236)
        at java.awt.Component.createBufferStrategy(Component.java:3567)
        at java.awt.Window.createBufferStrategy(Window.java:3012)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:844)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:795)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:728)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:505)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:263)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
        at javax.swing.JComponent.paint(JComponent.java:1013)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
        at java.awt.Container.paint(Container.java:1780)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
        at java.awt.image.Raster.createPackedRaster(Raster.java:458)
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
        at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:225)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:252)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:108)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:72)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:82)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:93)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:604)
        at java.awt.Component.createVolatileImage(Component.java:3316)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:4038)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3983)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4236)
        at java.awt.Component.createBufferStrategy(Component.java:3567)
        at java.awt.Window.createBufferStrategy(Window.java:3012)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:844)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:795)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:728)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:505)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:263)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
        at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
        at java.awt.image.Raster.createPackedRaster(Raster.java:458)
        at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
        at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:225)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:252)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:108)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:72)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:82)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:93)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:604)
        at java.awt.Component.createVolatileImage(Component.java:3316)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:4038)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3983)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4236)
        at java.awt.Component.createBufferStrategy(Component.java:3567)
        at java.awt.Window.createBufferStrategy(Window.java:3012)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:844)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:795)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:728)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:505)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:263)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
BUILD SUCCESSFUL (total time: 25 seconds)
+6  A: 

Increase the heap space. Java uses 64MByte heap memory if you don't specify a higher maximum. Start your application like this:

java -Xmx128m MyClass

to have 128MByte.


It look like you start the application within an ant build. I would separate building and execution. Let ant create a batch file which will be used to start the application.

Now you may have to increase heap space for ant itself. This is done with an environment variable (solution shown for windows):

set ANT_OPTS=-Xms512m -Xmx512m

Further Reading

Andreas_D
The default heap size depends on your JVM version, your JVM arguments and (in some cases) how much "physical" memory your "machine" has.
Stephen C
Indeed, the -X switches are JVM specific and may vary from JVM to JVM; the heap control switch shown is for the Sun (now Oracle) JVM, though in practice all JVMs are likely to use the same switch.
Software Monkey
+2  A: 

You can set Heap size using following options:

  -Xms32m -Xmx128m

check VM options here :

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

But I will suggest you to check whats consuming up your heap. You can do it using profiling tools like :

YoK
If it's image processing... it can be very consuming.
helios
A: 

Your JVM is running out of heap space. Try using the -Xmx switch to the JVM to increase the amount of heap space available to your program.

java -Xmx256m YourClassName 
Chinmay Kanchi
A: 

By default, without modifiyin JVM start params, you have 128m of heap space.

The memory allocated by your program is greater than this 128m.

You can increase your heap space limits:

java -Xms<initial heap size> -Xmx<maximum heap size>
SourceRebels
92MB on Java 6.
nhnb
A: 

I want to insert around 1 million records in one go. Am taking data from Oracle Db and inserting into Sybase Db. I'm getting the same exception while inserting.

So i tried inserting in batch. Now i'm doing executeBatch for a batch of 20000. It is taking so much time to execute executeBatch() and after some 100000 inserts the program hangs.

What could be the problem? Any other way to do this?

Jazz
You might want to ask another question @jazz, and link to this question rather than post this as an answer.
Paddyslacker
Add further explanations to your question instead adding them as an answer to your question.
Janusz
well....im fetching 147 records from mysql table so how is my memory getting used up??