|
In
your sample you have two String references str1 and str2 pointing to two
_different_ String objects pointing to _one_ literal "String". The literal
"String" is normally stored together with the program code and _not_ on the
heap, since it's content and size is known at compile time and will never
change. As such it never needs to be garbage collected, nor is there any
need for reference counting. The String objects "know" this (through the
constructor used by the program to create them).
When
the program enters the scope of str1 and str2, two normal String objects are
allocated (the code for this is generated automatically by the compiler). If you
would set them to null oder a different String object (str1 = null or str1
= "hello") then, assuming you haven't set any other references to the object
(str3 = str1), the "old" object would be marked for garbage
collection.
There's no magic behind it.
Regards
Kim
____________________________________________________ To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Be respectful! Clean up your posts before replying ____________________________________________________ |
- [jdjlist] Re: AW: RE: String and other classes Lesden, Kim
- [jdjlist] Re: AW: RE: String and other classes Kevin Mukhar
