|
|
|||||||
|
My gut feeling is that the early VMs did not bother to GC interned Strings, but I haven't done a systematic study of those. Running the first code snippet in Sun's 1.1.8 VM does not show identity hashcode change. This is not a very conclusive test, however, because the low level format of object handles changed between Sun's 1.x and v2 VMs. Still, you can put together a simple testcase that creates and interns a large number of Strings and after a few thousand of those the 1.1.8 VM runs out of memory (despite the fact that the interned Strings are not retained anywhere in bytecode). This (and the fact that the same thing does not happen in recent VMs) shows that 1.1.8 VM likely keeps all interned Strings forever. One of the points I was trying to make is that interning and GC'ing of String values are not mutually exclusive and it is even possible to snoop at how it happens in modern VMs. Thus, in a good VM String.intern() works like a weak map, which could be handy. |