HOw to free the memory?
I used a ArrayList l and put over 10000 float[512] in it
ArrayList l=new ArrayList();
for (int i=0;i<10000;i++)
{
float a[]=newfloat[512];
l.add(a);
}
later I want to free the memory used by l,
I use l=null;
I hope the Garbage Collection will free the memory.
But it seems doesn't work;
Can anyone tell me how to solve the problem?
[714 byte] By [
pete_he] at [2007-9-26 2:50:54]

Hi,
ArrayList l = new ArrayList(); (1)
l=null (2)
In your example above, a new object is created with the name 'l'. As per your code, you are not using that object for any other use.
So Once you have to set to l= null as in (2), the garbage collection starts automatically.
But if that l is used in any other variable,
For eg,
ArrayList m = l; (3)
Then this m should be referred to some other object, then only 'l' will make the garbage collection, even if you set null to 'l'.
I hope this will help you.
Thanks
Bakrudeen
in java, there is no way to clear an object memory by programmer.
yes, u can set the object to null and even call systsem.gc(). but that only asks the garbage collector to clear whatever unrefence memory that it thinks should be clear.
u can only pray that sun will come out with a better garbage collector like free() API in C++.