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 › premature OutOfMemoryError: java heap space
Page Index Toggle Pages: 1
premature OutOfMemoryError: java heap space (Read 1161 times)
premature OutOfMemoryError: java heap space
Sep 20th, 2007, 4:59pm
 
Hi.
I'm having a lot of issues with memory management in Processing. In particular, loading images seem to cause a lot of trouble for no particular reason (that I can think of).

My issue is as follows: I just want to show a splash image, admittedly quite big (3600x3600 currently) at the start of my app (external). This is done at the beginning of the program, so not much is loaded yet in memory. I only have some really small icons loaded, a couple of fonts and a few custom object instances.

My rationale is: with the given resolution and assuming 32 bits per pixel the whole image should take roughly 50Mb of memory when loaded. I have set -Xmx128M as arguments to the JVM so... why do I still get the OOMEs?
Is it that Processing itself is taking a lot of memory?

I can't think of anything else. Any ideas?

Edit: looking at the Windows task manager, it seems that my process is using 140Mb of memory! How come? Where do the excess 90Mb come from? How much does the JVM take? Oh so many questions... Tongue
Re: premature OutOfMemoryError: java heap space
Reply #1 - Sep 20th, 2007, 7:27pm
 
That's a really big image Smiley

I can't explain the extra memory needs fully, but decoding an image will allways take extra memory...

So, a couple of options:
1 - Use a smaller picture Wink
2 - Increase the java's memory
3 - Partition the image and load it piece by piece...
Re: premature OutOfMemoryError: java heap space
Reply #2 - Sep 20th, 2007, 11:59pm
 
Well, my post was not much about solving this particular issue (which I know I can solve by giving java more memory), but on the inefficiency of my application in general.

I'm not sure if this is a Processing issue, or a Java issue, or even _my_ issue, but clearly something is wrong here. How come that a simple slideshow type app like mine can take up to 250Mb, even when I only put one of the images in memory at a time?
And, strangely enough, most images are way smaller than the one I described but, for some crazy reason, the memory usage of my app never decreases! (acording to task manager). It stalls on about 250 to never come down again.

I really think this is weird. Anybody could point me to something I may be missing here?

Thanks.
Re: premature OutOfMemoryError: java heap space
Reply #3 - Sep 21st, 2007, 12:32am
 
Ah that's a Java thing. Java doesn't delete things from memory as soon as you stop refering to them. What it does is occasionably, when it's nearing the limit of it's memory, or at occasional points in time it runs something called the Garbage Collector.

The GC does the actal deleting, but even then I think Java sometimes keeps the memory allocated as you're likely to use it again in the near future.
Re: premature OutOfMemoryError: java heap space
Reply #4 - Sep 21st, 2007, 10:29am
 
Yep, I know about garbage collection. But the strange thing is, that I force collection by invoking System.gc() sometimes, but it seems to have no effect.
Re: premature OutOfMemoryError: java heap space
Reply #5 - Sep 21st, 2007, 11:04am
 
System.gc is only a suggestion to that GC to do stuff. If you've not run out of memory, it'll probably do nothing.

The windows "in-use" memory listing isn't telling you how much memory your program is actually using, since as I said, as long as you're below the memory limits, it may well only 'internally' free it, instead of externally so other programs can use it.
Page Index Toggle Pages: 1