Great question!
No. Both forms will (may be) GC'd because GC does not look for links in other links directly. It searches only for what is called the "Root" link ... This includes reference variables on the stack (the variable is on the stack, the actual object is, of course, on the heap), refers to variables in the processor registers and reference variables that are static fields in classes ...
All other reference variables are accessible only (and GC'd) if they refer to the property of one of the "root" reference objects found by the above process ... (or in the object referenced by the link to the root object, etc.)
So, only if one of the forms is mentioned somewhere else in the "root" link - then both forms will be safe from GC.
The only way I can come up with to “prove” it (without using the memory tracing utilities) would be to create a couple of hundreds of thousands of these forms, in a loop inside the method, then, while in the method, look at the application’s memory, then exit the method , call GC and look at the trail again.
Charles Bretana Dec 30 '09 at 16:23 2008-12-30 16:23
source share