Batch allows you to separate code that is fetching data and processing them in batches. It has many uses.
Write ten lines of 80 characters per line.
Batch is automatically flushed and reset when limit is reached and when is destroyed.
If no items were added to batch since start or last flush callback is not called.
You can flush batch manually at any point calling flush().
Or flush and throw away calling unset on batch.
Usually you don't have to unset since garbage collector will do it for you at the end of function.
If you are getting random errors after processing data via Batch make sure you flush it before doing anything else. You are probably assuming all data are flushed when there might be few left after last round.
Ie.: in Doctrine when processing entities don't forget to flush manually before calling $repository->clear();.