Java variables -> replace? RAM optimization

Posted by poeschlorn on Stack Overflow See other posts from Stack Overflow or by poeschlorn
Published on 2010-05-10T06:50:13Z Indexed on 2010/05/10 6:54 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about java

Related posts about ram