Uhm that is weird.
AFAIK, most operations of the stdlib are implemented using variables and while loops.
I just tested and can’t reproduce the problem like this:
LazyList.from(1).take(1000000).toSet // works!
LazyList.from(1).take(10000000).toSet // OutOfMemoryError: Java heap space.
So, I guess I would have blowup the stack before the heap.
Can you create a reproducible example?