Skip to content

Instantly share code, notes, and snippets.

@orionll
Created November 9, 2018 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orionll/162bc4ead5ce2c6ecbaae9b7298ba509 to your computer and use it in GitHub Desktop.
Save orionll/162bc4ead5ce2c6ecbaae9b7298ba509 to your computer and use it in GitHub Desktop.
public final class Main {
public static void main(String... args) throws Throwable {
Integer i = new Integer(1);
WeakReference<Integer> ref = new WeakReference<>(i);
System.gc();
System.out.println(ref.get());
myStupidReachabilityFence(i);
}
private static void myStupidReachabilityFence(Integer i) {
}
}
@cypok
Copy link

cypok commented Nov 9, 2018

import java.lang.ref.WeakReference;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment