Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.out of memory error

Tags:

java

memory

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)
like image 467
user424845 Avatar asked Aug 19 '10 06:08

user424845


2 Answers

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

  • Comprehensive Java HowTo for setting the Java heap space
like image 133
Andreas Dolk Avatar answered Oct 29 '22 18:10

Andreas Dolk


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 :

  • JProfiler
  • VisualVM
like image 26
YoK Avatar answered Oct 29 '22 20:10

YoK