Batching is a good idea as I mentioned on
It’s possible even 1k batches are too big, though not likely. Consider reducing the batch size to 500 or 250, say.
I’m not sure what’s causing you to run out of memory. What error message are you getting? It might be that the in-memory rowstore segment is getting too big. Normally it would flush automatically though, so that’s probably not it. But you could try running OPTIMIZE TABLE FLUSH after every 10 batches or so. That would flush the contents of the in-memory rowstore segment to disk.