/** * 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. */ private boolean cleanUp(Reference<?> reference) { Method finalizeReferentMethod = getFinalizeReferentMethod(); if (finalizeReferentMethod == null) { return false; } do { /* * This is for the benefit of phantom references. Weak and soft references will have already * been cleared by this point. */ reference.clear(); if (reference == frqReference) { /* * The client no longer has a reference to the FinalizableReferenceQueue. We can stop. */ return false; } try { finalizeReferentMethod.invoke(reference); } catch (Throwable t) { logger.log(Level.SEVERE, "Error cleaning up after reference.", t); } /* * Loop as long as we have references available so as not to waste CPU looking up the Method * over and over again. */ } while ((reference = queue.poll()) != null); return true; }
public void run() { while (true) { try { Reference<?> ref = queue.remove(); Resource res = null; synchronized (ResourceManager.this) { res = refs.get(ref); refs.remove(ref); } res.release(); ref.clear(); } catch (InterruptedException ex) { break; } } }
protected void orphanedMemory(Reference ref) { AddressWrapper wrapper; // BEGIN android-changed // copied from newer version of harmony synchronized (this) { PlatformAddress shadow = refToShadow.remove(ref); wrapper = memoryInUse.get(shadow); if (wrapper != null) { // There is a leak if we were not auto-freeing this memory. if (!wrapper.autoFree) { System.err.println( "Memory Spy! Fixed memory leak by freeing " + wrapper.shadow); // $NON-NLS-1$ } wrapper.shadow.free(); } } ref.clear(); // END android-changed }
@Override public void close() { closed = true; old.clear(); ref.clear(); }