It turned out during discussion about lightweight finalization (see JDK-8051843) that people often blame finalization for misbehavior which is not necessarily related to finalization, rather to VM behavior. In my opinion (as expressed at http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-August/028215.html ) it boils down to question whether following method can finish or not:
private void gcThis() {
Reference<?> ref = new WeakReference<>(this);
while (ref.get() != null) {
System.gc();
}
System.err.println("ref is gone: " + ref);
}
my personal suggestion is that it should never finish, however I am not the right person to decide that. Rather I just report this issue to track the decision made by others. I just want to express my developer wish: sometimes I want "this" to not be GCed while its instance method is running and it would be nice to have cross VM way to enforce that.
private void gcThis() {
Reference<?> ref = new WeakReference<>(this);
while (ref.get() != null) {
System.gc();
}
System.err.println("ref is gone: " + ref);
}
my personal suggestion is that it should never finish, however I am not the right person to decide that. Rather I just report this issue to track the decision made by others. I just want to express my developer wish: sometimes I want "this" to not be GCed while its instance method is running and it would be nice to have cross VM way to enforce that.
- duplicates
-
JDK-8133348 Reference.reachabilityFence
- Resolved
- relates to
-
JDK-8046178 JEP 188: Java Memory Model Update
- Draft
-
JDK-8133348 Reference.reachabilityFence
- Resolved