This issue can be recreated by copying the below code into a playground. You will see that in the first example below the publisher is not released when using .flatMap with Fail
In this second example, the publisher is released as expected using .tryMap with throw
Is this the expected behavior?
Code Block import Combine import Foundation struct SampleError: Error {} weak var weakPublisher: CurrentValueSubject<SampleError, Never>! autoreleasepool { let publisher = CurrentValueSubject<SampleError, Never>(SampleError()) weakPublisher = publisher publisher .flatMap(Fail<Void, SampleError>.init(error:)) .sink( receiveCompletion: { print("completed \($0)") }, receiveValue: { print("value \($0)") } ) .cancel() } assert(weakPublisher == nil, "should be nil BUT IS NOT !!!")
In this second example, the publisher is released as expected using .tryMap with throw
Code Block import Combine import Foundation struct SampleError: Error {} weak var weakPublisher2: CurrentValueSubject<SampleError, Never>! autoreleasepool { let publisher = CurrentValueSubject<SampleError, Never>(SampleError()) weakPublisher2 = publisher publisher .tryMap{ throw $0 } .sink( receiveCompletion: { print("completed \($0)") }, receiveValue: { print("value \($0)") } ) .cancel() } assert(weakPublisher2 == nil, "is nil as expected")
Is this the expected behavior?