When I subscribe({})
to an Observable in a Singleton class, do I need to call .dispose()
method at some point? and if yes, when and where? because a singleton will remain until the App is running.
something like this (Kotlin):
@Singleton
class MySingletonClass @Inject constructor(
private val api: MyAPIManager
) {
fun fetchData() {
//subscribed inside the Singleton
api.service.getSomeDataFromAPI()
.toRxObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
//do something internally with response
},
{
//handle error internally
})
}
the subscribe()
method returns a Disposable
.
My main question is: do I need to call dispose()
at all? because I think I only can call it when the App is finished or killed, which is not necessary.