Memory exhausted when downloading in csv format?

I download a csv file and create custom nodes. I've set the Drupal memory limit on 512 MB and I can see it in the Drupal status report. But when I download a csv file, the error message "Allowed memory of 536870912 bytes has run out (attempt to allocate 20480 bytes)" is displayed. The file I'm trying to download is only 26 MB. I use batching to create nodes. How to solve this problem of memory exhaustion? If, by increasing the memory, you can solve this problem, what is the recommended memory limit I should set?