public void deleteRemovedDeviceAndUpdateEndTime(Map<IDeviceID, Long> lastTimeForEachDevice) {
    ITimeIndex newTimeIndex = CONFIG.getTimeIndexLevel().getTimeIndex();
    for (Map.Entry<IDeviceID, Long> entry : lastTimeForEachDevice.entrySet()) {
      timeIndex
          .getStartTime(entry.getKey())
          .ifPresent(
              startTime -> {
                newTimeIndex.updateStartTime(entry.getKey(), startTime);
                newTimeIndex.updateEndTime(entry.getKey(), entry.getValue());
              });
    }
    timeIndex = newTimeIndex;
  }
the DeviceTimeIndex degrade to FileTimeIndex and release memory
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java