change RecordData to avoid oom problem and  close writer to flush results