MCPcopy Index your code
hub / github.com/java-native-access/jna / testAutoFreeMemory

Method testAutoFreeMemory

test/com/sun/jna/MemoryTest.java:42–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40public 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);

Callers

nothing calls this directly

Calls 5

shareMethod · 0.95
setIntMethod · 0.95
purgeMethod · 0.95
gcRunMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected