We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › java.lang.OutOfMemoryError: Java heap space
Page Index Toggle Pages: 1
java.lang.OutOfMemoryError: Java heap space (Read 4334 times)
java.lang.OutOfMemoryError: Java heap space
Jan 13th, 2006, 3:06pm
 
Hi,

I created a simple sketch that loads 30 jpeg images into a PImage array and then loops through them. Each jpeg is around 170Kb and I am running WinXP in a 3.2GHz P4 and have 1Gb RAM.

QUESTION 1)
Some frames after the loop starts I get this error: "Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space". If I lower the number of image to 15 then everything works fine. Using OPENGL the problem remains. What am I doing wrong here?

QUESTION 2)
Loading the 30 images takes quite a long time (around 4 or 5 seconds) considering it is such a simple thing. Why is it taking so long?

Note: pictures names are like this: Barbara0001.jpg, Barbara0002.jpg, Barbara0003.jpg, etc...

Here's the sketch:

>>>> BEGIN OF CODE >>>>>>>>>>>>>>>>>>

///////////////////////////////////////////////
// globals
///////////////////////////////////////////////
int MAX_NUM_IMAGES = 30;
String IMAGE_FILENAME = "images/Barbara";
int count = -1;
PImage[] images;

///////////////////////////////////////////////
// setup
///////////////////////////////////////////////
void setup()
{
 // Environment setup
 size(600,600);
 framerate(6);

 // Load images
 images = new PImage[MAX_NUM_IMAGES];
 for(int i=0;i<MAX_NUM_IMAGES;i++)
 {
   String name = "000" + i+1;
   name = name.substring(name.length()-4);
   images[i] = loadImage(IMAGE_FILENAME + name + ".jpg");
   println("image " + name + " loaded");
 }
}

///////////////////////////////////////////////
// draw
///////////////////////////////////////////////
void draw()
{
 count++;
 image(images[count], 0, 0);
 if (count == MAX_NUM_IMAGES-1)
   count = -1;
}

<<<<<<< END OF CODE <<<<<<<<<<<<<<<<<<<<<

Thanks in advance,
Nuno
Re: java.lang.OutOfMemoryError: Java heap space
Reply #1 - Jan 13th, 2006, 4:30pm
 
fixing memory errors:
http://processing.org/faq/bugs.html#memory

memory issues with opengl, third item:
http://processing.org/faq/bugs.html#opengl
Re: java.lang.OutOfMemoryError: Java heap space
Reply #2 - Jan 13th, 2006, 10:35pm
 
Thank you! Problem solved! No more memory error.

Pictures are still very slow to load. But although annoying, this doesn't stop me from continuing the project.

Nuno
Page Index Toggle Pages: 1