| 250 | // GoRefQueue is a queue of GoRefs that are no longer live. An internal thread |
| 251 | // processes the queue and decrement the reference count on the Go side. |
| 252 | static class GoRefQueue extends ReferenceQueue<GoObject> { |
| 253 | // The set of tracked GoRefs. If we don't hold on to the GoRef instances, the Java GC |
| 254 | // will not add them to the queue when their referents are reclaimed. |
| 255 | private final Collection<GoRef> refs = Collections.synchronizedCollection(new HashSet<GoRef>()); |
| 256 | |
| 257 | void track(int refnum, GoObject obj) { |
| 258 | refs.add(new GoRef(refnum, obj, this)); |
| 259 | } |
| 260 | |
| 261 | GoRefQueue() { |
| 262 | Thread daemon = new Thread(new Runnable() { |
| 263 | @Override public void run() { |
| 264 | while (true) { |
| 265 | try { |
| 266 | GoRef ref = (GoRef)remove(); |
| 267 | refs.remove(ref); |
| 268 | destroyRef(ref.refnum); |
| 269 | ref.clear(); |
| 270 | } catch (InterruptedException e) { |
| 271 | // Ignore |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | }); |
| 276 | daemon.setDaemon(true); |
| 277 | daemon.setName("GoRefQueue Finalizer Thread"); |
| 278 | daemon.start(); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // A GoRef is a PhantomReference to a Java proxy for a Go object. |
| 283 | // GoRefs are enqueued to the singleton GoRefQueue when no longer live, |
nothing calls this directly
no outgoing calls
no test coverage detected