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 & HelpSyntax Questions › dump unwanted array
Page Index Toggle Pages: 1
dump unwanted array (Read 666 times)
dump unwanted array
Aug 16th, 2009, 11:16am
 
if i have created an array that was being used at some point in my program, and now its not needed anymore, how can i dump it to free up memory?
Re: dump unwanted array
Reply #1 - Aug 16th, 2009, 11:57am
 
I'm sure this has been asked before.  IIRC the simplest option is something like:

Code:
int[] myArray = {1,2,3,4,5,6,7,8,9,0};

void setup() {
println(myArray.length);
myArray = new int[0];
println(myArray.length);
}
Re: dump unwanted array
Reply #2 - Aug 17th, 2009, 7:05am
 
Actually, you shouldn't care about freeing up the memory since this is Java's Garbage Collector purpose, but if you want to get rid of your array, just set it to null:

Code:
myArray = null; 

Re: dump unwanted array
Reply #3 - Aug 17th, 2009, 1:04pm
 
If the array is large and defined at top level, it can be interesting to hint the GC to collect it, assigning it to an empty array (as blindfish shows) with side advantage that code still works on it (.length and other) or to null (as you show, more radical...).
Page Index Toggle Pages: 1