RxDisposableWatcher — find leaked subscriptions in RxJava code 🐞

Overview

RxDisposableWatcher — find leaked subscriptions in RxJava code 🐞

Download Android Arsenal

The Problem

Consider the following RxJava code:

class Thermometer {
  fun observeTemperature(): Observable<Int>
}
// ...
val thermometer = Thermometer.getInstance()
// ...
thermometer
  .observeTemperature()
  .subscribe { /* ... */ } // Subscribed, but not disposed afterwards!

We subscribed to Thermometer instance but never released a Disposable resource later. As a result it can blow up an application logic or even cause a memory leak! 💩

🔥 Read my post on Medium: Detect Leaked Subscriptions in RxJava code with RxDisposableWatcher 🔥

Use RxDisposableWatcher plugin to find all undestroyed subscriptions & build the detailed HTML report:

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

Getting started

Setup

Gradle:

repositories {
    jcenter()
}

implementation 'ru.fomenkov:rx-disposable-watcher:x.y.z'

Maven:

<dependency>
  <groupId>ru.fomenkovgroupId>
  <artifactId>rx-disposable-watcherartifactId>
  <version>x.y.zversion>
  <type>pomtype>
dependency>

Please replace x.y.z with the latest version numbers:

Initialization

RxDisposableWatcher.init()

For Android application add storage permission into AndroidManifest.xml to save & pull generated HTML report:

">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

⚠️ Note: in case you're facing with IllegalStateException: Plugins can't be changed anymore, then another application component tries to use RxJavaPlugins utility class with exclusive access. Disable this component when working with the plugin.

Make snapshot & generate HTML report

Now you're ready to go! Check whether you have alive Rx subscriptions at the moment:

val result = RxDisposableWatcher.probe() // Collect info: stacktrace, number of calls, type
val report = HtmlReportBuilder(result).build() // Generate HTML report

For Android save the report to SD card:

val report = ...
val file = File(context.getExternalFilesDir(null), "report.html") // Specify filename
val stream = FileOutputStream(file)
stream.use { it.write(report.toByteArray()) }

Display HTML report in a desktop browser

Pull report file from Android device and display (replace with your paths):

adb pull /sdcard/report.html ~/report.html # Grab a report from SD card
open ~/report.html # for Mac
# or
google-chrome ~/report.html # for Linux

That's it!

Displaying HTML report in one click (Like a boss) 😎

I want a magic button in Android Studio toolbar to show HTML report in one click!

The idea is pretty simple:

As a lazy developer I prefer the described approach, because it dramatically saves my time!

How to add this button? 👉 Read the dedicated section in my post: Get a report in one click from Android Studio

Licence

Copyright 2020 Andrey Fomenkov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Find your new favorite wallpaper that looks just like you 🖌️
Find your new favorite wallpaper that looks just like you 🖌️

Wollpaper Find your new favorite wallpaper that looks just like you. Builds The pre-built app can be downloaded under "releases" on the right side of

Ride hailing app that helps users find drivers and take them from point A to point B.
Ride hailing app that helps users find drivers and take them from point A to point B.

Ride-hailing_rider_app Ride hailing app that helps users find drivers and take them from point A to point B. What I Used ? Clean Architecture : Basica

find the top coffee shop near by a given location
find the top coffee shop near by a given location

YelpCoffee&Tea 2 Different Activities (Screens): coffee shop List, coffee shop detail View Android app displays coffee shop locations in specified loc

Haven is an app to help people in need find resources.

Haven Haven is an app to help people in need find resources. Haven connects people to resources such as food pantries, homeless shelters, healthcare,

Main goal of this project is to find the best route from one country to another

Route-service Main goal of this project is to find the best route from one country to another. Data is presented as json format. I've implemented A* p

M-OV-ies - An Android Application that helps users find where to stream their favorite movies

Stream-ON Video Demo: Description: Final Project for CS50 - 2021: An Android App

An application to find out the weather according to the current location of the phone

Weather App An application to find out the weather according to the current loca

HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin centers etc.)
HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin centers etc.)

Android-Study-Jams-Hostel-Mate HostelMate - A Need For Hosteler (An Android App that helps students to find the best resource like hostels and tiffin

CheckInternetConnection - CheckInternetConnection helps to find out if user`s Android device is connected to Internet or not

Check Internet Connection CheckInternetConnection helps to find out if user`s An

A Burp extension to find stuff ¯\_(ツ)_/¯
A Burp extension to find stuff ¯\_(ツ)_/¯

FindStuffer FindStuffer, a Burp extension to find stuff, both for Community and Pro versions. You can use FindStuffer to aggregate as many text querie

An Android app to help runners to find races in France
An Android app to help runners to find races in France

Onirun Onirun was an Android app to help runners to find races in France. We were a team of 4 people to create the project on our free time : me for t

Helps to find your surrounding's light value (for android only) using device light sensor

react-native-ambient-light-sensor Helps to find your surrounding's light value (in lux unit) (for android only) using device light sensor Installation

Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuation of the Readme file. 🪞
Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuation of the Readme file. 🪞

Parallax Examples : Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuatio

Find Security Bugs is the SpotBugs plugin for security audits of Java web applications
Find Security Bugs is the SpotBugs plugin for security audits of Java web applications

The SpotBugs plugin for security audits of Java web applications and Android applications. (Also work with Kotlin, Groovy and Scala projects)

This application is purpose to help user find food or drink recipes.
This application is purpose to help user find food or drink recipes.

MyRecipes Let's Start Our Labs! This application is purpose to help user find food or drink recipes. Download App Features Explore Recipes Search Reci

Movo (Movie Information) is an android application to find out all the Movie Information and Details.

Movo About The Project Screen.Recording.2022-08-12.at.08.53.46_1.mp4 Movo (Movie Information) is an android application to find out all the Movie Info

Help find conflict in gradle.

Dependency Conflict Analyzer Gradle Plugin This plugin scans dependencies during gradle build. Throws an error if there is a possible dependency confl

IND appointment checker helps you to find some available slots in IND website.

IND Appointment Checker What is IND? The Immigration and Naturalisation Service (IND) assesses all residence permit applications from the people who w

Built the ccp code on compose. Country Code Picker is an android library which provides an easy way to search and select country or international phone code.
Built the ccp code on compose. Country Code Picker is an android library which provides an easy way to search and select country or international phone code.

Built the ccp code on compose. Country Code Picker is an android library which provides an easy way to search and select country or international phone code.

Owner
Andrey Fomenkov
Software Engineer
Andrey Fomenkov
Map-vs-list-comparator - The project compares the time needed to find a given element in a map vs the time needed to find a given element in a list.

Map vs List Comparator The project compares the time needed to find a given element in a map vs the time needed to find a given element in a list. To

null 0 Jan 4, 2022
Android common lib demo, include ImageCache, HttpCache, DropDownListView, DownloadManager, install apk silent and so on, you can find description

android-demo 关于我,欢迎关注 微博:Trinea 主页:trinea.cn 邮箱:trinea.cn#gmail.com 微信:codek2 依赖:trinea-android-common android-auto-scroll-view-pager viewpager-indica

Trinea 1.1k Nov 10, 2022
Android common lib demo, include ImageCache, HttpCache, DropDownListView, DownloadManager, install apk silent and so on, you can find description

android-demo 关于我,欢迎关注 微博:Trinea 主页:trinea.cn 邮箱:trinea.cn#gmail.com 微信:codek2 依赖:trinea-android-common android-auto-scroll-view-pager viewpager-indica

Trinea 1.1k Dec 30, 2022
This is a practice app. An app that you can find random recipes and choose the ones you like.

A food suggestion app like Tinder This is a practice app. In this app, you can find random recipes and choose the ones you like. This is main menu. Yo

Yunus Emre OCAK 4 May 25, 2022
Android Project to find FatMax in real time with a Polar H10

FatMaxxer According to recent research (see below) the FatMaxxer Android app may help you to exercise at the optimum effort level for fat burning, mea

null 37 Dec 28, 2022
Protect yourself from being tracked 🌍 by AirTags 🏷 and Find My accessories 📍

AirGuard - AirTag tracking protection Protect yourself from Find My Tracking The AirTags and other Find My devices are simple, small and perfect to tr

Secure Mobile Networking Lab 1.4k Jan 9, 2023
A program analysis tool to find cryptographic misuse in Java and Android.

A program analysis tool to find cryptographic misuse in Java and Android.

null 92 Dec 15, 2022
A manga reader app that can be used save / search / find and read latest manga / manhwa

A manga reader app that can be used save / search / find and read latest manga / manhwa

Sebin P Johnson 3 Nov 20, 2021
Find your dream Job - built with MVVM ,GraphQL ,Glide, Shimer

nextJob Find your dream Job The idea of the application is to help users find job opportunities and internships that exist on the internet in an organ

inaciosacataria 3 Mar 18, 2022