JUnit @After teardown and WeakReference usage for reliable memory leak detection
When writing a JUnit test that aims to confirm a memory leak has been fixed, a common approach is to hold a java.lang.ref.WeakReference to the suspect object, clear strong references, and then check that the reference has been cleared. The goal is to assert that after the test’s teardown phase (e.g., an @After or @AfterEach method) the weakly‑referenced obje