title: swift combine sink receiveValue memory leak
body: <p>I'm having a hard time with dealing with Combine. After the publisher is complete I want to update a value but whenever I update that value the memory is allocated and never goes away.</p>
  
  <p>Whenever I try to assign image there is a leak. If I don't assign no leak.</p>
  
  <p>EDIT: Reproducible example here: <a href="https://github.com/peterwarbo/MemoryAllocation" rel="noreferrer">https://github.com/peterwarbo/MemoryAllocation</a></p>
  
  <p>This is what my code looks like:</p>
  
  <pre><code>final class CameraController: ObservableObject {
  
      private var storage = Set&lt;AnyCancellable&gt;()    
      var image: UIImage?
  
      func capture(_ image: UIImage) {
  
          PhotoLibrary.saveImageToTemporaryDirectory(image) // AnyPublisher&lt;URL, Error&gt;
              .zip(PhotoLibrary.saveImage(image, location: self.locationObserver.location) // AnyPublisher&lt;UIImage, Error&gt;)
              .sink(receiveCompletion: { [weak self] (completion) in
                  switch completion {
                  case let .failure(error):
                      Log.error(error)
                      self?.handleCaptureError(error)
                  case .finished: break
                  }
              }) { [weak self] (value) in
                  print(value.1) // no leak
                  self.image = value.1 // leak
  
              }
              .store(in: &amp;self.storage)
       }
  }
  </code></pre>
  
  <p>I've also tried instead of using <code>sink</code>:</p>
  
  <pre><code>.receive(
      subscriber: Subscribers.Sink(
          receiveCompletion: { [weak self] completion in
              switch completion {
              case let .failure(error):
                  Log.error(error)
                  self?.handleCaptureError(error)
              case .finished: break
              }
          },
          receiveValue: { value in
              print(value.1) // no leak
              self.image = value.1 // leak            
          }
      )
  )
  </code></pre>