Fix memory leak

Delete output_instance after use to prevent memory leak, which can cause a crash on very long jobs.