Results 1 to 6 of 6
- 03-19-2013, 12:13 AM #1
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
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
multiple times (with different names of course). After almost ~230 of the above code repeated we get the error.Java Code:ImageIcon m13_1i = new ImageIcon("./M13/1.jpg"); Card m13_1 = new Card("Ajani, Caller of the Pride", m13_1i, "M13");
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
- 03-19-2013, 09:56 AM #2
Godlike
- Join Date
- Nov 2012
- Posts
- 194
- Rep Power
- 1
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).
- 03-19-2013, 01:39 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,470
- Rep Power
- 16
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.
- 03-19-2013, 08:12 PM #4
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
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
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:)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");Last edited by Sotsiak91; 03-19-2013 at 08:19 PM.
- 03-19-2013, 08:56 PM #5
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)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-20-2013, 10:57 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,470
- Rep Power
- 16
Similar Threads
-
Performance tuning to eliminate java.lang.OutOfMemoryError: Java heap space - JTable
By Redefine12 in forum New To JavaReplies: 1Last Post: 05-04-2012, 07:21 PM -
java.lang.OutOfMemoryError: Java heap space Workaround
By hudrv in forum Advanced JavaReplies: 4Last Post: 09-18-2011, 08:17 PM -
java.lang.OutOfMemoryError:Java heap space
By newbiejava in forum New To JavaReplies: 3Last Post: 08-22-2010, 09:00 AM -
how to solve this ERROR --java.lang.OutOfMemoryError: Java heap space
By krunalpatel1410 in forum New To JavaReplies: 5Last Post: 08-13-2010, 10:04 AM -
java.lang.OutOfMemoryError: Java heap space
By vidjogamer in forum New To JavaReplies: 3Last Post: 02-06-2009, 06:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks