ios - RxSwift `.addDisposableTo(disposeBag)` causes memory leak -
i using heavily in companies project rxswift. , when running performance tests in instrument worrying problem appeared.
each time .adddisposableto(disposebag)
gets called, instruments show memory leak around 10 bytes. there's no specific pattern of why happen, not using [weak self]
in right places, happens no apparent reason.
some sample code:
class contactsviewmodel: nsobject { fileprivate let disposebag = disposebag() fileprivate let provider = authorizednetworking().provider var contacts: variable<[user]> = variable([]) var suggestedcontacts: variable<[user]> = variable([]) func fetchcontact(suggestions: bool = false) { activityindicator.showloadinghud(message: "fetching contacts...") let observable = provider.request(suggestions ? .suggest : .searchcontacts(query: nil, global: false)).filtersuccessfulstatuscodes() let mapped = observable.checkforerrors().mapobject(datalistresponse<user>.self) mapped.subscribe { [weak self] event in switch event { case let .next(response): activityindicator.hideloadinghud() if response.success, let contacts = response.data { if suggestions { self?.suggestedcontacts.value = contacts } else { self?.contacts.value = contacts.filter { $0.contacttype == "friend" } } } else { log(.network, .error, "unable retrieve current user") } case let .error(error): activityindicator.hideloadinghud() log(.network, .error, error.localizeddescription) default: break } }.adddisposableto(disposebag) <- instruments show leak [6 bytes] @ line } }
i've done research , have 1 version instrument might not understand rxswift , make there's leak in reality, there isn't. implementation has problems don't know of since have little experience in rxswift. appreciated.
Comments
Post a Comment