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 › OutOfMemoryError: been there, done that...
Page Index Toggle Pages: 1
OutOfMemoryError: been there, done that... (Read 596 times)
OutOfMemoryError: been there, done that...
Jun 12th, 2009, 11:21am
 
So here's the deal. In my twitter project I'm drawing a bunch of tweets to the screen to float around and change sizes and stuff. I'm getting OutOfMemory errors when I draw only around 20 tweets to the screen. Each call to text() creates a bitmap image of the string data, right? Well the absolute largest any of these bitmaps would be is maybe 400X200, and probably even smaller than that.

I've encountered the dreaded OutOfMemoryError many times before and have read all the documentation and bug reports on the subject and how you shouldn't draw a ton of images, etc., etc. So my question is, I'm on a machine running Vista 64-bit, with 6GB of RAM installed, and my Processing preferences are only requesting 1610MB of that (the highest it will allow me to go). Is 1610MB really not enough to load 20ish 400X200 bitmaps? I mean what's causing Processing to lose all this memory? The displayed text has changing alpha values and colors and sizes. Is all this extra info effecting the file size of each text bitmap?

Like I said, I've read up a ton on this stuff, but never quite understood why it actually happens. Is Processing not disposing of old frames/images or something? If I dial the amount of tweets down to something like 10, it'll run for about 5-10 minutes, but then crash with the memory error. I've read some similar-sounding bug reports, but what I would like to know is how to go about optimizing my code to avoid this sort of stuff. Can someone at least explain to me how Java/Processing handles images that might cause these errors?
Re: OutOfMemoryError: been there, done that...
Reply #1 - Jun 12th, 2009, 12:44pm
 
The question is a bit too generic. For example, drawing text might depend on the graphics mode (OpenGL, Java2D, P2D, P3D) and even the text mode.

You might exhaust the memory by many means, some you might control, others perhaps not.
A call to text() doesn't create a bitmap image, it just draw the image of letters to screen, with the bitmap font (vlw) or the vector TTF one (in Java2D mode). The latter might take some memory but we cannot control that since that's Java (AWT) which does that.
Re: OutOfMemoryError: been there, done that...
Reply #2 - Jun 12th, 2009, 1:34pm
 
Oh, duh, I forgot, that's the point of creating fonts. Thanks for the reminder. Well I found something in my code which was a no no. This project is an upgrade from an earlier project. In the old version I was using size 80 font to display a few big messages. When I converted it over to the new stuff, I never actually loaded a new, smaller font. Now I'm using a size 20 and my issues have vanished for now.

I guess what I was kind of wondering was how Processing/Java handles changing images. So if I use text() to call up a string of character bitmaps, but then change the text at some point, what happens to the original string of bitmaps? Are they disposed of immediately or do they hang around in the memory until exit? Or do I have this all wrong and the memory required is only the amount that it required to load the vlw file? I'm just kind of trying to learn what happens behind the scenes that allows us to do this stuff so easily.
Re: OutOfMemoryError: been there, done that...
Reply #3 - Jun 12th, 2009, 2:19pm
 
Again, it depends. In Java2D mode, it will derive the font to the indicated size, which might be memory intensive.
In the other modes, it will just scale the character image when drawing it, so no memory extra.
Note also memory print of a font depends on the number of characters used while creating it.
Re: OutOfMemoryError: been there, done that...
Reply #4 - Jun 12th, 2009, 2:39pm
 
OK, thanks for your responses, PhiLho. I think I'm going to dig into some Java resources to learn some more about this stuff.
Page Index Toggle Pages: 1