| 40 | public class MemoryTest extends TestCase { |
| 41 | |
| 42 | public void testAutoFreeMemory() throws Exception { |
| 43 | Memory core = new Memory(10); |
| 44 | Pointer shared = core.share(0, 5); |
| 45 | Reference<Memory> ref = new WeakReference<>(core); |
| 46 | |
| 47 | core = null; |
| 48 | System.gc(); |
| 49 | assertNotNull("Base memory GC'd while shared memory extant", ref.get()); |
| 50 | // Avoid having IBM J9 prematurely nullify "shared" |
| 51 | shared.setInt(0, 0); |
| 52 | |
| 53 | shared = null; |
| 54 | long start = System.currentTimeMillis(); |
| 55 | System.gc(); |
| 56 | Memory.purge(); |
| 57 | for (int i=0;i < GCWaits.GC_WAITS && ref.get() != null;i++) { |
| 58 | GCWaits.gcRun(); |
| 59 | } |
| 60 | long end = System.currentTimeMillis(); |
| 61 | assertNull("Memory not GC'd after " + (end - start) + " millis", ref.get()); |
| 62 | } |
| 63 | |
| 64 | public void testShareMemory() { |
| 65 | Memory base = new Memory(8); |