How to leak memory with Subscriptions in RxJava

Marcin Robaczyński
5 min readFeb 17, 2017

Look out!

This article is outdated as it covers and old version of RxJava— you can find the updated version for RxJava2 here: https://medium.com/@scanarch/how-to-leak-memory-with-disposables-in-rxjava2-715dd80bf966

— — — — — — — —

There are plenty of great how-to articles about RxJava. It does simplify things significantly when working with Android framework but be careful because simplification may have its own pitfalls. In the following parts, you are going to explore one of them and see how easy it is to create a memory leak with RxJava’s Subscriptions.

Solving simple task

Imagine that your manager called in and asked you to create a widget which displays a random movie title. It has to be based on some external recommendation service. This widget should display a movie title on user’s demand or it could do it on its own. The manager also wants this widget to be able to store some information related to user’s interaction with it.

MVP-based approach is one of the many ways to do this. You create a simple view containing bothProgressBar andTextView widgets. The RecommendedMovieUseCase handles providing a random movie title.
Presenter connects to a use case and displays a title on a view. Saving presenter’s state is…

--

--