Detect Leaked Subscriptions in RxJava code using RxDisposableWatcher

The Problem

Error handling, subscribeOn(…) and observeOn(…) operators are omitted for simplicity.

Discover leaks with RxDisposableWatcher 🐞

Everything we need: stack trace, number of calls & Observable types.

Setup

Typical usage example

Gotcha! There are 7 alive subscriptions created by WeatherActivity at line 9
Dispose a resource in onDestroy()

Get a report in one click from Android Studio 😳

[ 1 ] Shell script

The script is well commented. Update variables with your own values!

[ 2 ] BroadcastReceiver event handler

[ 3 ] Adding a magic button to Android Studio toolbar

Looks very nice, isn’t it? ☝️
Preferences → Tools → External Tools

References

Software Engineer