title: What happens if my DispatchGroup never finishes
body: <p>I have many asynchronous tasks that need to all be completed before I can move on, so I'm using a DispatchGroup. However, I am able to tell if one of the tasks fails early, and I would usually call a completion handler.</p>
  
  <p>If I leave the scope of the function by calling a completion handler, what happens to the DispatchGroup?</p>
  
  <p>Is the memory allocated forever? Is it possible that if leave is called enough times eventually (maybe due to a bug) that the notify block can still be called?</p>
  
  <p>Example:</p>
  
  <pre><code>func example(completion: @escaping (Bool) - Void) {
      let group = DispatchGroup()
  
      group.enter()
      asyncFunction1 {
          if result == false {
              completion(false)
          } else {
              group.leave()
          }
      }
  
      group.enter()
      asyncFunction2 { result in
          if result == true {
              group.leave()
          }
      }
  
      group.notify(queue: .main) {
          completion(true)
      }
  }
  </code></pre>
  
  <p>In the example above I have two asynchronous functions. The first function might call <code>completion(false)</code>, and the second function only calls <code>leave</code> on success. While it might not be the best example of code, these conditions are possible. What happens to the notify block?</p>