Does scala maintains the values of variable by copy or reference?
For example, in Ruby “the closure will actually extend the lifetime of all the variables that it needs. It will not copy them, but will retain a reference to them and the variables themselves will not be eligible for garbage collection (if the language has garbage collection) while the closure is around”. [SKORKIN]
Closures in Scala also don’t deep copy objects, they’ll only keep a reference to the object. Moreover, a closure does not get it’s own lexical scope, but instead, it uses the surrounding lexical scope.
I can’t comment on garbage collection, but I assume that the JVM’s garbage collector will not remove objects that are referenced by a closure, as long as the closure is still referenced.