@Override public boolean disposeIfUnreferenced() { if (this.getNumReferences() == 0) { assert !this.isDisposed() : String.format("%s has already been disposed.", this); logger.debug("Discarding {} for being unreferenced.", this); this.disposeUnreferenced(); this.isDisposed = true; return true; } return false; }
@Override public void noteDiscardedReference(boolean isDisposeIfUnreferenced) { assert this.numReferences > 0 : String.format("Reference on %s discarded, although the reference counter is 0.", this); this.numReferences--; logger.trace("{} has {} (-1) references now.", this, this.getNumReferences()); if (isDisposeIfUnreferenced) { this.disposeIfUnreferenced(); } }
@Override public void noteObtainedReference() { assert !this.isDisposed() : String.format("%s should not be resurrected.", this); this.numReferences++; logger.trace("{} has {} (+1) references now.", this, this.getNumReferences()); }