# Java Heap Problem



## MC DarkMaster (12. Okt 2008)

Hallo Leute,

kann mir einer sagen, was ich falsch mache, wenn ich folgende Fehlermeldung bekomme:

```
Exception occurred during event dispatching:
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:214)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:247)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:103)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:66)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:76)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:81)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:569)
        at java.awt.Component.createVolatileImage(Component.java:3209)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:3864)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3809)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4065)
        at java.awt.Component.createBufferStrategy(Component.java:3455)
        at java.awt.Window.createBufferStrategy(Window.java:2968)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:858)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:815)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:738)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:513)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:271)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
        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:1797)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
Exception occurred during event dispatching:
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:214)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:247)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:103)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:66)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:76)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:81)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:569)
        at java.awt.Component.createVolatileImage(Component.java:3209)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:3864)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3809)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4065)
        at java.awt.Component.createBufferStrategy(Component.java:3455)
        at java.awt.Window.createBufferStrategy(Window.java:2968)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:858)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:815)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:738)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:513)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:271)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
        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:1797)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
Exception occurred during event dispatching:
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:214)
        at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:247)
        at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:103)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:66)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:76)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:87)
        at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:81)
        at sun.awt.windows.WComponentPeer.createVolatileImage(WComponentPeer.java:569)
        at java.awt.Component.createVolatileImage(Component.java:3209)
        at java.awt.Component$BltBufferStrategy.createBackBuffers(Component.java:3864)
        at java.awt.Component$BltBufferStrategy.<init>(Component.java:3809)
        at java.awt.Component$BltSubRegionBufferStrategy.<init>(Component.java:4065)
        at java.awt.Component.createBufferStrategy(Component.java:3455)
        at java.awt.Window.createBufferStrategy(Window.java:2968)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:858)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.createBufferStrategy(BufferStrategyPaintManager.java:815)
        at javax.swing.BufferStrategyPaintManager$BufferInfo.getBufferStrategy(BufferStrategyPaintManager.java:738)
        at javax.swing.BufferStrategyPaintManager.prepare(BufferStrategyPaintManager.java:513)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:271)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
        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:1797)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:734)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
```

Ich hab ein kleines Spiel geschrieben und wenn ich ca. 10 Fenster öffne (Fenster in dem Spiel, zum Beispiel kleines InfoFenster in dem der aktuelle Spielstatus angezeigt wird) , bleibt das Fenster durchsichtig und der Fehler erscheint.
Ich hoffe einer von euch kann mir hier weiterhelfen.


----------



## Fu3L (12. Okt 2008)

10 Fenster hört sich viel an, hast du mal einen Aufruf mit 

-Xms128m -Xmx1024m

versucht? Dadurch erhält die Java-VM mehr Speicher. Standartmäßig sinds maximal 128 MB. So erhält die VM von Anfang an 128 MB und hat maximal ein GB zur Verfügung...


----------



## Guest (12. Okt 2008)

Fu3L hat gesagt.:
			
		

> 10 Fenster hört sich viel an, hast du mal einen Aufruf mit
> 
> -Xms128m -Xmx1024m
> 
> versucht? Dadurch erhält die Java-VM mehr Speicher. Standartmäßig sinds maximal 128 MB. So erhält die VM von Anfang an 128 MB und hat maximal ein GB zur Verfügung...



Sry, habs falsch formuliert. Ich rufe nicht 10 Fenster auf einmal auf, sondern nur ein Fenster 10 Mal hintereinander. (oder andere Fenster). Aber nie zur gleichen Zeit. Das heißt ich geh irgendwo hin, ein Fenster geht auf, dann verlass ich das fenster wieder, geh wo anders hin und dort kommt wieder ein Fenster. Nach 10 Mal will er dann nicht mehr. 

Wie kann ich den Aufruf unter Netbeans machen?


----------



## MC DarkMaster (12. Okt 2008)

Ich bin jetzt selbst drauf gekommen. Während ich den letzten Post geschrieben habe ist mir aufgefallen, dass ich die Fenster nur "unsichtbar" mache mit this.setVisible(false); aber im Endeffekt gar nicht schließe. Darum hat nur ein simpler this.dispose(); gefehlt


----------

