public void close()

in src/main/java/com/spotify/sparkey/ReadOnlyMemMap.java [111:140]


  public void close() {
    final MappedByteBuffer[] chunks;
    final boolean onlyUser;
    synchronized (allInstances) {
      if (this.chunks == null) {
        return;
      }
      chunks = this.chunks;
      onlyUser = allInstances.size() == 1;
      for (ReadOnlyMemMap map : allInstances) {
        map.chunks = null;
        map.curChunk = null;
      }
      Sparkey.decrOpenFiles();
      Util.nonThrowingClose(randomAccessFile);
    }
    if (!onlyUser) {
      // Wait a bit with closing so that all threads have a chance to see the that
      // chunks and curChunks are null. If the sleep time is too short, the JVM can crash
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
    Sparkey.decrOpenMaps();
    for (MappedByteBuffer chunk : chunks) {
      ByteBufferCleaner.cleanMapping(chunk);
    }
  }