Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Last active June 22, 2020 14:26
Show Gist options
  • Select an option

  • Save mbrandonw/4959480547b5b07b8f381e5a0a1479c4 to your computer and use it in GitHub Desktop.

Select an option

Save mbrandonw/4959480547b5b07b8f381e5a0a1479c4 to your computer and use it in GitHub Desktop.

FB7746024

Memory leak in Combine when using Concatenate with MergeMany

When you concatenate two publishers, one of which is a merge, you will get a leak reported in Xcode’s memory graph debugger.

The publisher can be as simple as:

self.cancellable = Publishers.Concatenate(
  prefix: Empty<Int, Never>(completeImmediately: true),
  suffix: Publishers.MergeMany(Empty(completeImmediately: true))
)
  .print()
  .sink { _ in }

I have a project attached that shows the problem. Simply launch the application and open the memory graph debugger to see the leaks. The pertinent code is in the SceneDelegate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment