code: private void cleanState(long index) {
      // If the keep alive index is set, release the entry.
      if (keepAliveIndex > 0) {
        log.release(keepAliveIndex);
      }
  
      context.sessions().unregisterSession(id);
  
      // If no references to session commands are open, release session-related entries.
      if (references == 0) {
        log.release(id);
        if (index > 0) {
          log.release(index);
        }
      } else {
        this.closeIndex = index;
      }
    }
docs: Cleans session entries on close.