Java variables -> replace? RAM optimization
- by poeschlorn
Hi guys,
I just wanted to know what happens behind my program when I declare and initialize a variable and later initialize it again with other values, e.g. an ArrayList or something similar.
What happens in my RAM, when I say e.g. this:
ArrayList<String> al = new ArrayList<String>();
...add values, work with it and so on....
al = new ArrayList<String>();
So is my first ArrayList held in RAM or will the second ArrayList be stored on the same position where the first one has been before? Or will it just change the reference of "al"?
If it is not replaced...is there a way to manually free the RAM which was occupied by the first arraylist? (without waiting for the garbage collector)
Would it help to set it first =null?
Nice greetings,
poeschlorn