void releaseMemory(@Nonnegative long size) {
        if (size == 0) {
            return;
        }
        boolean released = false;
        long currentAvailableMemorySize = 0L;
        while (!released
                && totalMemorySize
                        >= (currentAvailableMemorySize = availableMemorySize.get()) + size) {
            released =
                    availableMemorySize.compareAndSet(
                            currentAvailableMemorySize, currentAvailableMemorySize + size);
        }
        if (!released) {
            throw new IllegalStateException(
                    String.format(
                            "Trying to release more managed memory (%d bytes) than has been allocated (%d bytes), the total size is %d bytes",
                            size, currentAvailableMemorySize, totalMemorySize));
        }
    }
@Test
    void testReleaseMemory() throws MemoryReservationException {
        UnsafeMemoryBudget budget = createUnsafeMemoryBudget();
        budget.reserveMemory(50L);
        budget.releaseMemory(30L);
        assertThat(budget.getAvailableMemorySize()).isEqualTo(80L);
    }