public static void free(ByteBuffer... segments) throws IOException {
    try {
      // attempt to force-unmap the file, so we can delete it later
      // https://stackoverflow.com/questions/2972986/how-to-unmap-a-file-from-memory-mapped-using-filechannel-in-java
      Class<?> unsafeClass;
      try {
        unsafeClass = Class.forName("sun.misc.Unsafe");
      } catch (Exception ex) {
        unsafeClass = Class.forName("jdk.internal.misc.Unsafe");
      }
      Method clean = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
      clean.setAccessible(true);
      Field theUnsafeField = unsafeClass.getDeclaredField("theUnsafe");
      theUnsafeField.setAccessible(true);
      Object theUnsafe = theUnsafeField.get(null);
      for (ByteBuffer buffer : segments) {
        if (buffer != null && (buffer instanceof MappedByteBuffer || buffer.isDirect())) {
          clean.invoke(theUnsafe, buffer);
        }
      }
    } catch (Exception e) {
      throw new IOException("Unable to unmap", e);
    }
  }
Attempt to force-unmap a list of memory-mapped file segments, so it can safely be deleted.
<p>
Can also be used to force-deallocate a direct byte buffer.

@param segments The segments to free
@throws IOException If any error occurs freeing the segment
planetiler-core/src/main/java/com/onthegomap/planetiler/util/ByteBufferUtil.java