Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As a very simple rule of thumb, an object in java can be garbage collected if the program's behaviour <em>would not change</em> if all the fields of the object were copied to local variables ( an optimising program transformation ) and all references to the object were set to null.</p> <p>Quoting 'The Java VM Spec'</p> <blockquote> <p>12.6.1 Implementing Finalization Every object can be characterized by two attributes: it may be reachable, finalizer-reachable, or unreachable, and it may also be unfinalized, finalizable, or finalized.</p> <p>A reachable object is any object that can be accessed in any potential continuing computation from any live thread. Optimizing transformations of a program can be designed that reduce the number of objects that are reachable to be less than those which would naively be considered reachable. For example, a compiler or code generator may choose to set a variable or parameter that will no longer be used to null to cause the storage for such an object to be potentially reclaimable sooner.</p> <p>Discussion</p> <p>Another example of this occurs if the values in an object's fields are stored in registers. The program may then access the registers instead of the object, and never access the object again. This would imply that the object is garbage.</p> </blockquote> <p>So in your case, as none of the references to any of the <code>Icelandic</code> objects are dereferenced, all of them may be garbage collected immediately . As nothing dereferences <code>i1</code> to <code>i3</code>, an optimising compiler is at liberty to elide everything after <code>i3 = new Icelandic()</code> as a no-op and collect all six objects immediately. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload