Cleans up a single reference. Catches and logs all throwables. @return true if the caller should continue, false if the associated FinalizableReferenceQueue is no longer referenced.
(Reference<?> reference)
| 134 | */ |
| 135 | |
| 136 | private boolean cleanUp(Reference<?> reference) { |
| 137 | Method finalizeReferentMethod = getFinalizeReferentMethod(); |
| 138 | if (finalizeReferentMethod == null) { |
| 139 | return false; |
| 140 | } |
| 141 | do { |
| 142 | /* |
| 143 | * This is for the benefit of phantom references. Weak and soft references will have already |
| 144 | * been cleared by this point. |
| 145 | */ |
| 146 | reference.clear(); |
| 147 | if (reference == frqReference) { |
| 148 | /* |
| 149 | * The client no longer has a reference to the FinalizableReferenceQueue. We can stop. |
| 150 | */ |
| 151 | return false; |
| 152 | } |
| 153 | try { |
| 154 | finalizeReferentMethod.invoke(reference); |
| 155 | } catch (Throwable t) { |
| 156 | logger.log(Level.SEVERE, "Error cleaning up after reference.", t); |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Loop as long as we have references available so as not to waste CPU looking up the Method |
| 161 | * over and over again. |
| 162 | */ |
| 163 | } while ((reference = queue.poll()) != null); |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Looks up FinalizableReference.finalizeReferent() method. |