How does memory management for Scala collections work? -


i can't figure out implementation of operations scala's immutable sequences. i'll use example:

def example: list[int] = {   val list0 = list.range(1,10)    list0.tail } 

once function finishes executing list0 out of scope. list0's head removed memory, or list0 stay same until entire list garbage collected?

in example, head of list0 left garbage collector collect, nothing reference it. remaining items (the tail), however, continue exist upon exiting function (provided result of call assigned something).

each cell in list maintains reference next cell in list (or nil), not vice versa.


Comments