title: How does memory management for Scala collections work?
body: <p>I can't figure out the implementation of some operations for Scala's immutable sequences. I'll use this as an example:</p>
  
  <pre><code>def example: List[Int] = {
    val list0 = List.range(1,10)
  
    list0.tail
  }
  </code></pre>
  
  <p>Once the function finishes executing list0 is now out of scope. Would list0's head be removed from memory, or would list0 stay the same until the entire list is garbage collected?</p>