ylliX - Online Advertising Network

Disposables Can Cause Memory Leaks

02 Feb 2021 • 3 min read Every Disposable holds a strong reference to the observer it binds. This can lead to surprising memory leaks. Consider the following example: class TacoViewModel : ViewModel() { var compositeDisposable = CompositeDisposable() fun loadTaco(activity: Activity) { compositeDisposable.add( Single.just(Taco()) .subscribe { taco -> // Handle taco… println(“Taco created in […]