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 › Loading/displaying images ... Java heap space
Page Index Toggle Pages: 1
Loading/displaying images ... Java heap space (Read 515 times)
Loading/displaying images ... Java heap space
Aug 26th, 2006, 11:21pm
 
Hi all

I get an error:
Exception in thread "Thread-2" java.lang.OutOfMemoryError: Java heap space
after I run my program for a few seconds.

It's an application that just displays images (small ones) as a slide show. Very simple. Strangely it seems like it's doing something with RAM as my sound program starts to glitch when I run the processing program. (and only my program. All other processing sketches (i.e. without image loading) run fine).

I think it has to do with displaying images.

here is my loading code:

   for(int i = 0; i < imgNum; i++){
     if(i > 8) { // there is no image 000.bmp
       imgArray[i] = "0"+(i+1)+".jpg"; // and I'm adding 1 here
     }
     else {
       imgArray[i] = "00"+(i+1)+".jpg";
     }
   }

And I load them on setup, so there is no harddisk loading when the program runs. This takes around 6-7 seconds.

Then here is my image displaying code (inside draw())

   if(millis() > nextImgChangeMS) {
     nextImgChangeMS = millis() + (9000 + random(4000)) * speed;
     myPImage = pImgArray[(int)random(imgNum-1)];
     image(myPImage, 0, random(760));
   }

Extremely simple !!!

Where does the memory error come from? Is there not a garbage collection working here? It seems as all the old images stack up in RAM and fill it.

I searched the forum and Googled the problem and I found that this could be a solution:
run.options= -Xms128m -Xmx1024m

But it doesn't work.
Anyway, why should it require more ram? It loaded all the images fine and I'm only replacing an image into an image object on each draw.

(and my framerate is 12, so this shouldn't be a problem). CPU running on 24%.

If anyone could give a tip. I'd love to hear it.

Cheers
Re: Loading/displaying images ... Java heap space
Reply #1 - Aug 27th, 2006, 11:34am
 
I'm not sure but try :
Code:

image(pImgArray[(int)random(imgNum-1)], 0, random(760));
Re: Loading/displaying images ... Java heap space
Reply #2 - Aug 27th, 2006, 6:46pm
 
re: memory, there are two ways of changing the memory settings, you may have the wrong one:
http://processing.org/faq/bugs.html#memory
Re: Loading/displaying images ... Java heap space
Reply #3 - Aug 27th, 2006, 9:37pm
 
Apart from changing memory settings (which didn't help), the question remains:

Why am I getting memory problems when displaying images in the same image object. (And all the images were already loaded into the image array)?

All the images are the same size and format.

The program runs for 3-4 minutes and then it crashes. It seems that
image(new_image, ...)
is not garbage collecting the old image and just piling it up in memory.
Could that be?

Otherwise I'm puzzled.
cheers
Page Index Toggle Pages: 1