image - Weird "java.lang.OutOfMemoryError: Java heap space" -


today did simple java application, should load .png files memory (total space of these files ~7mb), makes weird error:

(my tiny command: java -xmx1024m -jar dist/pngimageloader.jar)

loaded image (0) images/image_01000111100000011000000110100000 loaded image (1) images/image_00000101010101101101000111111101 loaded image (2) images/image_01001110110011110011111001000000 loaded image (3) images/image_01001111000111010110101101001111 loaded image (4) images/image_00011100000011100011001011011100 loaded image (5) images/image_01010010001010001010110110110110 loaded image (6) images/image_01101100010001000001000110101111 loaded image (7) images/image_01010111011011101010101110100010 loaded image (8) images/image_01101101110100001011001011101100 loaded image (9) images/image_01100010111110011011100001000011 loaded image (10) images/image_00011111011000111101101111101111 loaded image (11) images/image_00000100111001010110101001110001 loaded image (12) images/image_01000001100111011101101011011011 loaded image (13) images/image_01100111000010000001011101111001 loaded image (14) images/image_01101000011011000001111010001100 loaded image (15) images/image_00010010110100001011000111111000 loaded image (16) images/image_00111100111011101101101001000101 loaded image (17) images/image_01111110001010111100011000000110 loaded image (18) images/image_00010111101011100011101101101000 loaded image (19) images/image_00101000001111110110000110101101 loaded image (20) images/image_01110101110000010000000000001001 loaded image (21) images/image_01001000101010101010000010100011 loaded image (22) images/image_00110111100001110011010011011001 loaded image (23) images/image_00001010001001000001101001001011 loaded image (24) images/image_00101111000110011000110011111000 loaded image (25) images/image_00101100010101000011001101010111 loaded image (26) images/image_01101111101000010111011000011010 loaded image (27) images/image_00111011111100000111100000000011 loaded image (28) images/image_01100100000101111111001000111101 loaded image (29) images/image_01001101110111111011000101000011 loaded image (30) images/image_00110010111010000111111011100101 loaded image (31) images/image_00111001110100011100101111111011 loaded image (32) images/image_01100011101111010111110110001111 loaded image (33) images/image_01000000110111000000010100010011 loaded image (34) images/image_00110101000001001101100010101001 loaded image (35) images/image_01001101011011010110100110111010 loaded image (36) images/image_00010111010100110100011111110101 loaded image (37) images/image_01011111011001111010000000111000 loaded image (38) images/image_00110001100110011111000010110001 loaded image (39) images/image_01110101010001111001011000000011 exception in thread "main" java.lang.outofmemoryerror: java heap space @ java.awt.image.databufferbyte.(databufferbyte.java:92) @ java.awt.image.componentsamplemodel.createdatabuffer(componentsamplemodel.java:415) @ java.awt.image.raster.createwritableraster(raster.java:941) @ javax.imageio.imagetypespecifier.createbufferedimage(imagetypespecifier.java:1073) @ javax.imageio.imagereader.getdestination(imagereader.java:2896) @ com.sun.imageio.plugins.png.pngimagereader.readimage(pngimagereader.java:1280) @ com.sun.imageio.plugins.png.pngimagereader.read(pngimagereader.java:1577) @ javax.imageio.imageio.read(imageio.java:1448) @ javax.imageio.imageio.read(imageio.java:1308) @ pngimageloader.images.loadimage(images.java:22) @ pngimageloader.images.getimage(images.java:33) @ pngimageloader.images.getallimages(images.java:43) @ pngimageloader.pngimageloader.main(pngimageloader.java:15)

here pngimageloader.java class,

package pngimageloader;  public class pngimageloader {      public static void main(string[] args) {         images images = new images();         images.getallimages("images/");     } } 

here images.java class..

package pngimageloader;  import java.awt.image.bufferedimage; import java.io.file; import java.util.hashmap; import javax.imageio.imageio;  public class images {      hashmap images;      images() {         images = new hashmap();     }      bufferedimage loadimage(string path) {         try {             return imageio.read(new file(path));         } catch (exception exception) {             system.out.println(exception.getmessage());             system.exit(1);             return null;         }     }      bufferedimage getimage(string path) {         bufferedimage image = (bufferedimage) images.get(path);         if (image == null) {             image = loadimage(path);             images.put(path, image);         }         return image;     }      void getallimages(string path) {         file files = new file(path);         int = 0;         (file file : files.listfiles()) {             getimage(file.getpath());             system.out.println("loaded image (" + + ") " + file.getpath());             i++;         }     } } 

i'm unprofessional, think it's weird. in advance help, patrick.

as gsp pointed out small files can expanded lots of memory. things should not keep images in memory, there never reason so. use sort of streaming stuff, dependending on want do.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -