this library can detect instance is called from GC.
add your gradle script
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
implementation 'com.github.satoshun.RxGC:rxgc:$latest_version'for kotlin
implementation 'com.github.satoshun.RxGC:rxgc-kotlin:$latest_version'Object target = new Object();
RxGC.watch(target)
.subscribeOn(Schedulers.io())
.subscribe(() -> Log.d("did Garbage Collection"));