I'm imagining that in the foreach loop, you are persisting data outside the code logic you have.
Can you update the question to contain the logic in comment:
//Do stuff with $row
Because if you save data outside of that statement, it remains in memory. So while you have an optimization in regards to chunking the
DB::SELECT(...)
The memory leak remains since data is likely aggregated outside of the relevant code you provided.