private void setSavedSegment(SegmentFd segment, RTResources rtResources) {
        this.savedSegment = segment;
        if (rowsInMemory != zeroRows) {
            Map<UTF8Row, UTF8Row> map = rowsInMemory;
            long memory = rowsMemoryUsage;

            rowsInMemory = zeroRows;
            rowInMemoryCount = 0;
            rowsMemoryUsage = 0;

            // Remove all rows and free its memory, help GC.
            Iterator<UTF8Row> it = map.values().iterator();
            while (it.hasNext()) {
                UTF8Row row = it.next();
                row.free();
            }
            map.clear();
            Preconditions.checkState(map.isEmpty(), "Realtime rows map should be emptpy now.");
            rtResources.decMemoryUsage(memory);
        }
    }
Persistence rows in memory to local disk.
indexr-segment/src/main/java/io/indexr/segment/rt/RealtimeSegment.java