Java VM Specification
12.6.1 Implementation of completion Each object can be characterized by two attributes: it can be accessed, the finalizer is available or inaccessible, and it can also be non-finalized, finalized or finalized.
A reachable object is any object that can be accessed in any potential ongoing computation from any live stream . You can optimize program conversions that reduce the number of objects that are achievable, less than those that are naively considered accessible. For example, a compiler or code generator may choose to set a variable or parameter that will no longer be used for a null value in order to more quickly restore the potential storage of such an object earlier.
Discussion
Another example of this occurs if the values โโin the fields of objects are stored in registers. Then the program can access the registers instead of the object and never access the object again. This would mean that the object is garbage.
An object is available if it can be involved in any potential ongoing calculation. Therefore, if your code refers to a local variable, and nothing else refers to it, you can force the object to assemble by setting it to null. This will either result in a null pointer exception, or change the behavior of your program, or if you donโt have it either, then you do not need a variable in the first place.
If you nullify a field or an element of an array, this may make sense for some applications, and this will lead to the fact that the memory will be fixed faster. Once a case creates a large array to replace the existing array referenced by the field in the class, if the field is in zero order before creating the replacement, it can reduce the pressure on the memory.
Another interesting feature of Java is that the region does not appear in class files, so the region is not related to reachability; these two methods create the same bytecode, and therefore, the virtual machine does not see the area of โโthe created object at all:
static void withBlock () { int x = 1; { Object a = new Object(); } System.out.println(x+1); } static void withoutBlock () { int x = 1; Object a = new Object(); System.out.println(x+1); }
Pete Kirkham May 28 '10 at 17:42 2010-05-28 17:42
source share