Results 1 to 6 of 6
  1. #1
    Sotsiak91 is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default java.lang.OutOfMemoryError: Java heap space

    Hello, I'm kinda new to Java and I need your help. I try to make with my friends a new app for a game we like. Anyways..
    at some point we get the following error message "Exception in thread "Image Fetcher 3" java.lang.OutOfMemoryError: Java heap space".

    In our code we have the following
    Java Code:
    ImageIcon m13_1i = new ImageIcon("./M13/1.jpg");
    Card m13_1 = new Card("Ajani, Caller of the Pride", m13_1i, "M13");
    multiple times (with different names of course). After almost ~230 of the above code repeated we get the error.
    I believe it is because of the too many ImageIcons and something with memory. How can I solve this??

    P.S. After some google I changed netbeans.conf file to this:
    netbeans_default_options="-J-client -J-Xss1m -J-Xms256m -J-Xmx768m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true"
    (I change the xss/xms/xmx values) The error changed a bit but is still there.

    P.S. Should I use another way to display my images other than ImageIcon?

    Thanks in advance

    The exact error is
    Java Code:
    Exception in thread "Image Fetcher 3" java.lang.OutOfMemoryError: Java heap space
     at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
     at java.awt.image.Raster.createPackedRaster(Raster.java:470)
     at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
     at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:253)
     at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:554)
     at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:138)
     at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:114)
     at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
     at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:136)
     at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269)
     at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
     at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
     at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
     at java.awt.image.Raster.createPackedRaster(Raster.java:470)
     at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
     at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:253)
     at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:554)
     at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:138)
     at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:114)
     at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
     at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:136)
     at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269)
     at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
     at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
    Exception in thread "Image Fetcher 2" java.lang.OutOfMemoryError: Java heap space
     at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
     at java.awt.image.Raster.createPackedRaster(Raster.java:470)
     at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
     at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:253)
     at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:554)
     at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:138)
     at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:114)
     at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
     at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:136)
     at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269)
     at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
     at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
     at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
     at java.awt.image.Raster.createPackedRaster(Raster.java:470)
     at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
     at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:253)
     at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:554)
     at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:138)
     at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:114)
     at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
     at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:136)
     at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269)
     at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
     at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Do you really have to adjust the NetBeans setting? Isn't this something you need to change in the run configuration for this application inside Netbeans?

    If memory stays a problem, you should cache any icons that are the same and reuse them. Maybe use a graphics program to reduce the size of the icon. If you like to fix things with a hammer, you can increase the -Xmx even more, about 1200-1300m is possible on a 32bit JRE. On 64bit JRE's there is no theoretical limit (besides the memory in the system itself).

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: java.lang.OutOfMemoryError: Java heap space

    How big (in pixels) are these images?
    Are you loading the same image several times (see SurfMans post about cacheing)?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Sotsiak91 is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Re: java.lang.OutOfMemoryError: Java heap space

    Ok I solved it, I removed all ImageIcon objects, from now on I create them only when I want to show an image. So everything is fine.

    EDIT: I wonder if I can ask a new question here because somehow it relates to my original problem. Anyways:
    I have some code like this
    Java Code:
    Card M13_1 = new Card("Ajani, Caller of the Pride", "1.jpg", "M13");
         
            Card M13_2 = new Card("Ajani's Sunstriker",  "2.jpg", "M13");
                    
            Card M13_3 = new Card("Angel's Mercy",  "3.jpg", "M13");
                    
            Card M13_4 = new Card("Angelic Benediction",  "4.jpg", "M13");
                   
            Card M13_5 = new Card("Attended Knight",  "5.jpg", "M13");
                
            Card M13_6 = new Card("Aven Squire",  "6.jpg", "M13");
                    
            Card M13_7 = new Card("Battleflight Eagle",  "7.jpg", "M13");
                    
            Card M13_8 = new Card("Captain of the Watch",  "8.jpg", "M13");
                  
            Card M13_9 = new Card("Captain's Call",  "9.jpg", "M13");
                    
            Card M13_10 = new Card("Crusader of Odric",  "10.jpg", "M13");
    I create a new Object like the above, 1000 times and I don't exaggerate, I noticed that it needs much time for the program to start-up. Because I'm a newbie in programming is the above method right, should I use another way to create the Objects? Is there any trick to improve the performance? Also I have an array table with all those objects. Thanks:)
    Last edited by Sotsiak91; 03-19-2013 at 08:19 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default Re: java.lang.OutOfMemoryError: Java heap space

    1. Follow coding conventions. Variable names should start with a lowercase letter => Code Conventions for the Java Programming Language: Contents

    2. Learn to use arrays instead of sequential variable names => Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: java.lang.OutOfMemoryError: Java heap space

    What does the constructor for Card do?
    Because a thousand basic objects with three reference attributes will not take long to create at all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 05-04-2012, 07:21 PM
  2. Replies: 4
    Last Post: 09-18-2011, 08:17 PM
  3. java.lang.OutOfMemoryError:Java heap space
    By newbiejava in forum New To Java
    Replies: 3
    Last Post: 08-22-2010, 09:00 AM
  4. Replies: 5
    Last Post: 08-13-2010, 10:04 AM
  5. java.lang.OutOfMemoryError: Java heap space
    By vidjogamer in forum New To Java
    Replies: 3
    Last Post: 02-06-2009, 06:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •