title: Lifetime of retained memory in Swift closures
body: <p>In the Advanced Swift talk from WWDC 2014, the speaker gave this example of a function memoizer using generics:</p>
  
  <pre><code>func memoize&lt;T: Hashable, U&gt;( body: (T)-&gt;U ) -&gt; (T)-&gt;U {
      var memo = Dictionary&lt;T, U&gt;()
      return { x in
          if let q = memo[x] { return q }
          let r = body(x)
          memo[x] = r
          return r
      }
  }
  </code></pre>
  
  <p>I'm having trouble wrapping my head around the lifetime of that <code>memo</code> var. Does each invocation of the memoized <code>fibonacci</code> function hold a strong reference to it? And if so, how would you release that memory when you're done with it?</p>