Posts

Showing posts with the label rx-swift

Reactive API Call on tap button produces a leak

Reactive API Call on tap button produces a leak I know it's not the best use-case but let's say I have a button which calls an API Service every time is tapped. Something like this: ViewController myButton.tap.flatMap { [unowned self] _ in return self.webService.apiCall() }.suscribe(someObserver) .disposed(by: self.disposeBag) WebService class WebService { func apiCall() -> Observable<[Result]> { return RxAlamofire.requestData(.get, url).map { [unowned self] response, data -> [MyResult] in return self.parse(data) } } } So I'm using every tap to request some information. Now, every observable is unique and inmutable and every tap would generate a new Observable I'm subscribing to. Am I wrong or doesn't it mean that I have a leak here and every requested observable (that is, every API call) isn't being disposed? What would it be an elegant way to solve this? Thanks in advance 1 ...