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 › [solved] how to free memory from unused data
Page Index Toggle Pages: 1
[solved] how to free memory from unused data? (Read 657 times)
[solved] how to free memory from unused data?
Mar 5th, 2008, 8:37pm
 
Hei,

i have an applet that seems too heavy on memory needs.
In the setup() method, i load 450 pictures (less than 10Ko each) dispatched in 16 arrays. These pictures are displayed sequentially; Basically, pictures from the three first arrays during 30 first seconds, next 30 seconds display pictures from a second group of three array, and so on.

I would like to know if i can 'clear' the arrays from memory after they have been used, as their content is not needed anymore?

This would, i hope, prevent my applet to hang on an OutOfMemory error after some time running.

Re: how to free memory from unused data?
Reply #1 - Mar 7th, 2008, 5:15pm
 
I'm not sure on this, but as far as I know, you would have to make each array location point to "null".

This way, when the garbage collector catches the unused image data, it will automatically free it for you.

You could even make an array for the first 90 seconds and then overwrite the first 30 seconds, then the second 30 seconds, then the third, then start again; instead of using a "new 30 second" array.
Re: how to free memory from unused data?
Reply #2 - Mar 8th, 2008, 1:18pm
 
oh, thanks ^^
i redifined the size of useless arrays like this:
 myArray = new PImage[0];
and it worked perfectly. Plus, i also had to divide the loading of pictures along the time instead of loading everything in the setup() method.

One thing i was missing is that a jpeg file, once loaded in memory, takes the size of a full uncompressed pixel matrix.

My problem is solved now, and the applet working perfectly.

thank you!
Page Index Toggle Pages: 1