Memory leak in Combine when using Concatenate with MergeMany

Here's a straightforward way to create a leak in Combine:

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

Just concatenate a publisher with a suffix that is a MergeMany. Interestingly if you swap the prefix and suffix the leak disappears, but then of course the publisher has substantially changed.

I filed a feedback about this (FB7746024), but posting here too to make sure there isn't something simple I'm missing.

3 Likes

Thanks for posting this @mbrandonw! Just curious if you've heard anything from Apple about this?

Is it still leaking? I don't see anything on Instrument.

I was testing on iOS 13.5, and the leak was there. Going to check later versions.

Looks like the issue is gone starting from Xcode 12 (iOS 14). That means all iOS 13 version are affected (was able to reproduce this in Xcode 11.7).