Additional Information
Creating and clearing tasks outside looping structures is considered a best practice to avoid unnecessary memory allocation and improve performance. You can see this in action by looking through the shipping examples in the NI Example Finder.
You can also let the NI-DAQmx driver manage its own de-allocation by enabling auto cleanup on the DAQmx Create Task.vi. If the auto cleanup parameter is set to true, the resources allocated in task creation will be freed when the VI completes. If auto cleanup is set to false, the resources will be freed when LabVIEW exits.