MCPcopy Create free account
hub / github.com/java-native-access/jna / WeakMemoryHolder

Class WeakMemoryHolder

src/com/sun/jna/WeakMemoryHolder.java:40–55  ·  view source on GitHub ↗

Helper to hold a memory object based on the lifetime of another object. The intended use is to assoziate a ByteBuffer with its backing Memory object. The ByteBuffer is held by a WeakReference and a ReferenceQueue is used to track GC of the ByteBuffer. The references to the memory objects are rele

Source from the content-addressed store, hash-verified

38 * The references to the memory objects are released on access of WeakMemoryHolder.
39 */
40public class WeakMemoryHolder {
41 ReferenceQueue<Object> referenceQueue = new ReferenceQueue<>();
42 IdentityHashMap<Reference<Object>, Memory> backingMap = new IdentityHashMap<>();
43
44 public synchronized void put(Object o, Memory m) {
45 clean();
46 Reference<Object> reference = new WeakReference<>(o, referenceQueue);
47 backingMap.put(reference, m);
48 }
49
50 public synchronized void clean() {
51 for(Reference ref = referenceQueue.poll(); ref != null; ref = referenceQueue.poll()) {
52 backingMap.remove(ref);
53 }
54 }
55}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…