private void removeReferenceStack(final Throwable referenceStack, final Throwable releaseStack) {
        final boolean doDestroy;
        synchronized (activeReferences) {
            final boolean wasThere = activeReferences.containsKey(referenceStack);
            activeReferences.remove(referenceStack);
            if (!wasThere) {
                throw new IllegalStateException("Reference is already released and can only be released once."
                        + " reference=" + Arrays.toString(referenceStack.getStackTrace())
                        + ". State={ " + currentState() + "}");
            }
            doDestroy = activeReferences.isEmpty();
            log.log(Level.FINE, releaseStack,
                    () -> getClass().getName() + "@" + System.identityHashCode(this) + " release: state={ " + currentState() + " }");
        }

        if (doDestroy) {
            resource.close();
        }
    }
Does reference counting by putting stacktraces in a map together with an optional context.
Intended only for debugging as it is slow.
Used if system property jdisc.debug.resources=stack

@author baldersheim
jdisc_core/src/main/java/com/yahoo/jdisc/refcount/DebugReferencesWithStack.java