free temporary array at once instead of step-by-step