Clean all references stored in referenceList, regardless of whether they are in referenceQueue or not.
()
| 68 | * <b>regardless</b> of whether they are in {@code referenceQueue} or not. |
| 69 | */ |
| 70 | @SuppressWarnings("StatementWithEmptyBody") |
| 71 | public void forceClear() { |
| 72 | // Decrement all reference counters |
| 73 | Reference<?> cur = referenceList.next; |
| 74 | while (cur.next != null) { |
| 75 | cur.decRef(ctx, cur.nativePtr); |
| 76 | cur = cur.next; |
| 77 | } |
| 78 | |
| 79 | // Bulk-delete the reference list's entries |
| 80 | referenceList.next = cur; |
| 81 | cur.prev = referenceList; |
| 82 | |
| 83 | // Empty the reference queue so that there are no living phantom references anymore. |
| 84 | // This makes sure that all stored phantom references can be GC'd now. |
| 85 | while (referenceQueue.poll() != null) {} |
| 86 | } |
| 87 | |
| 88 | private static Reference<?> emptyList() { |
| 89 | Reference<?> head = new DummyReference(); |