Hi,
There is a term in Scala that is Lazy evaluation which is used for the spark to get rid of huge memory allocation. You can see the example below to see no memory allocation:
scala> lazy val x = (1 to 1000) .toList
You will get the same output but there will be no memory allocation to the var x.