Forked from ChristinGorman/gist:67be1561c20b2fdaf0d5
Last active
August 29, 2015 14:18
-
-
Save kimble/874304cac45ea31f4018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.lang.ref.WeakReference; | |
import static org.junit.Assert.*; | |
public class PubSubTest { | |
@Test | |
public void notWtf() { | |
WeakReference<Runnable> reference = new WeakReference<Runnable>(new Runnable() { | |
@Override | |
public void run() { | |
// ... | |
} | |
}); | |
forceGc(); | |
assertNull(reference.get()); | |
} | |
@Test | |
public void lambdaWtf() { | |
WeakReference<Runnable> reference = new WeakReference<Runnable>(() -> Integer.valueOf(1) ); | |
forceGc(); | |
assertNull(reference.get()); | |
} | |
public void forceGc() { | |
try { | |
Object[] ignored = new Object[(int) Runtime.getRuntime().maxMemory()]; | |
} catch (Throwable e) { | |
// Ignore OME | |
} | |
System.gc(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment