title: Swift weak reference going nil even when self keeps existing
body: <p>I'm trying to figure out why is a weak reference losing its referenced object even after the object keeps existing.</p>
  
  <p>My code looks like:</p>
  
  <pre class="lang-swift prettyprint-override"><code>MyClass {
      deinit {
          print("I'm being deinited") // This never gets called
      }
      func doConnection(connection: Future&lt;Data, ServerConnectionError&gt;) {
          Future&lt;Void, ServerConnectionError&gt; { complete in
              connection.onSuccess {[weak self] data in
                  guard let strongSelf = self else {
                      return // This line gets called
                  }
                  ...
              }
          }
      }
  }
  </code></pre>
  
  <p>By inspecting the memory graph, I can see that the object referenced by self before the future completes is still alive (judging by the memory address).</p>
  
  <p>Here's what the memory graph for the supposedly missing object looks like after finding its weak reference as nil (MyClass instance in far right):</p>
  
  <p><a href="https://i.stack.imgur.com/nUoSx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nUoSx.png" alt="Memory graph showing two main references to the object"></a></p>
  
  <p>The upper subtree is the one supposed to hold the object alive, while the bottom one has to do with the current stack execution. The object (blue box) that is referenced by many others in the 3rd level (from right to left) holds a strong reference to an array, which in turn holds a reference to the MyClass instance.</p>
  
  <p><strong>EDIT</strong>: Problem solved in answer below. Will mark as solved after cooldown passes.</p>