Reputation: 792
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));
}
}
Upvotes: 1
Views: 669
Reputation: 11010
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.
Upvotes: 3