title: Why doesn't changing a closure property to a function cause the same retain cycle?
body: <blockquote>
    <p>A strong reference cycle can also occur if you assign a closure to a
    property of a class instance, and the body of that closure captures
    the instance.</p>
  </blockquote>
  
  <p>If closures as properties can cause strong retain cycles, and functions are a type of closure according to the <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-ID94" rel="nofollow noreferrer">Swift programming guide</a>: </p>
  
  <blockquote>
    <p>Global and nested functions, as introduced in Functions, are actually
    special cases of closures</p>
  </blockquote>
  
  <p>Why doesn't changing a closure property to an instance method cause the same retain cycle?  </p>
  
  <blockquote>
    <p>Instance methods are functions that belong to instances of a
    particular class, structure, or enumeration. </p>
  </blockquote>
  
  <p>For example, as is, the code below does not deallocate the instance of HTMLElement, however, if I change <code>asHTML</code> to a function instead of a name for a closure expression, the <code>HTMLElement</code> is deallocated.  </p>
  
  <pre><code>class HTMLElement {
      let name: String
      let text: String?
      lazy var asHTML: () -&gt; String = {
          return "&lt;\(self.name)&gt;\(self.text ?? "")&lt;/\(self.name)&gt;"
      }
  
      init(name: String, text: String? = nil) {
          self.name = name
          self.text = text
      }
      deinit {print("\(name) is being deinitialized")}
  }
  
  var headerTitle: HTMLElement? = HTMLElement(name: "h1", text: "Welcome")
  print(headerTitle!.asHTML())
  headerTitle = nil
  </code></pre>
  
  <p>Debugger: </p>
  
  <pre><code>&lt;h1&gt;Welcome&lt;/h1&gt;
  </code></pre>
  
  <p>When changed to a function: </p>
  
  <pre><code>func asHTML() -&gt; String {
      return "&lt;\(self.name)&gt;\(self.text ?? "")&lt;/\(self.name)&gt;"
  }
  </code></pre>
  
  <p>Debugger: </p>
  
  <pre><code>&lt;h1&gt;Welcome&lt;/h1&gt;
  h1 is being deinitialized
  </code></pre>