Hi Vladax,
Ok, no worries.
Like I already suspected, an array variable uses a LOT of memory in PHP ...
Read this interesting article:
https://nikic.github.io/2011/12/12/How-big-are-PHP-arrays-really-Hint-BIG.html
So it is no memory leak issue.
Just not a good idea to read all table data at once into an array ...
So now I understand why solution #2 works.
Thanks for your contribution to this issue. Well done
dwinden