public void checkForLeaks() {
        Set<Handle> leakedHandles = handleTracker.leakedElements();

        if (!leakedHandles.isEmpty()) {
            fail(format("Found %d leaked handles.", leakedHandles.size()));
        }

        int leakedCleanablesCount = 0;

        for (RecordingContext<Cleanable> context : contextElements.values()) {
            Set<Cleanable> leakedCleanables = context.leakedElements();
            if (!leakedCleanables.isEmpty()) {
                leakedCleanablesCount += leakedCleanables.size();
            }
        }

        if (leakedCleanablesCount > 0) {
            fail(format("Found %d leaked cleanable objects in %d contexts", leakedCleanablesCount, contextElements.size()));
        }
    }
A simple leak checker that tracks statement context and cleanable resource management.
core/src/test/java/org/jdbi/v3/core/junit5/JdbiLeakChecker.java