Combine Publisher + SwiftUI = MemoryLeak

We are seeing a memory leak when using a combine TimePublisher (as in the code below) to trigger a fade out of a view.

This is pretty simplified, but I'm struggling to see where we are going wrong. Removing the onAppear block or changing it to set showRedView to false directly removes the leak.

It seems directly tied to our use of the publisher.

Code Block
class ContentViewModel: ObservableObject {
    @Published var showRedView = true
    var subscriptions: Set<AnyCancellable> = []    
    func fadeRedView() {
        Timer.publish(every: 5.0, on: .main, in: .default)
            .autoconnect()
            .prefix(1)
            .sink { [weak self] _ in
                withAnimation {
                    self?.showRedView = false
                }
            }
            .store(in: &subscriptions)
    }
}
struct ContentView: View {
    @ObservedObject var viewModel = ContentViewModel()
    var body: some View {
        ZStack {
            if viewModel.showRedView {
                Color.red
                    .transition(.opacity)
            }
            Text("Hello, world!")
                .padding()
        }
        .onAppear {
            self.viewModel.fadeRedView()
        }
    }
}


We are seeing this leak in both Xcode 11 and Xcode 12, so doesn't seem related to the current beta.

Any help is appreciated as always, thanks!
Looks like the leak is caused by using the prefix operator. Removing it resolves the leak 100%.

Radar filed - FB8365664 (Memory leak when using the prefix operator with a TimerPublisher)
I have some code that is very similar. In my case I am reading a large file in a background thread and updating the published property (rather than using a timer). But I get the same result - a memory leak. After about 400 updates my memory usage doubles. I've tried using autoreleasepools in my ContentView. However, they don't seem to have any effect.
Combine Publisher + SwiftUI = MemoryLeak
 
 
Q