See the following kotlin code:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val disposable = Observable.interval(1, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
.subscribe { textView.text = it.toString }
}
}
Here I am am passing a lambda expression in the subscribe method instead of an anonymous inner classses. So is it required to call disposable.dispose()
in order to prevent memory leaks? Or the lambda expression won't keep an implicit reference to the instance of the MainActivity class.
And if I do need to dispose it, what is the best way and why?