I would like to do something like this:
class MyWeakReference<T> extends WeakReference<T> {
void onClear() { .. run my code .. }
}
But since GC doesn't call clear()
, but sets the referent to null directly, it seems like there is no way to invoke such code.