Images use too much RAM in Processing

Jachdich :

I'm trying to load a few thousand small images into processing and display them as a larger map. The total filesize of the images together is 130MiB however when I run the program it uses all of my RAM and I even get an OutOfMemoryError as the RAM usage exceeds 2GiB.

What causes over 10x the memory usage compared to the filesize, and is there any way I can mitigate this?

EDIT:

Example code

ArrayList<PImage> images = new ArrayList<PImage>();
void setup() {
    for (int i = 0; i < 2000 /*num of images*/; i++) {
        images.add(loadImage(Integer.toString(i) + ".jpg");
    }
}

//in reality, never gets here
void draw() {

    for (PImage i: images) {
        image(i, /*precalculated x and y*/ random(500), random(500));
    }
}
mnistic :

JPEG compression ratio is 10:1, so that would explain it: the images are compressed on disk, but when loaded into your program and decompressed you get 10 times the size.

To improve your code, don't load the images all at once: process them few at a time.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357&siteId=1