-
MonetCompat is a singleton that stores its own instance in the INSTANCE field. The problem is that MonetCompatActivity creates it by passing itself as context. As a result, when the activity is destroyed, it remains bound to MonetCompat and cannot be released by the garbage collector.
-
The MonetCompat registers the BroadcastReceiver in the setup method if running on Android 12 or older versions of Android. The MonetCompatActivity calls setup on creation by passing itself to it as context. However, when the activity is destroyed, this BroadcastReceiver is not unregistered, which leads to activity leakage.
For me, the only way to avoid these leaks is to stop using MonetCompatActivity and initialize MonetCompat myself using the application context.
MonetCompatis a singleton that stores its own instance in theINSTANCEfield. The problem is thatMonetCompatActivitycreates it by passing itself as context. As a result, when the activity is destroyed, it remains bound toMonetCompatand cannot be released by the garbage collector.The
MonetCompatregisters theBroadcastReceiverin thesetupmethod if running on Android 12 or older versions of Android. TheMonetCompatActivitycallssetupon creation by passing itself to it as context. However, when the activity is destroyed, thisBroadcastReceiveris not unregistered, which leads to activity leakage.For me, the only way to avoid these leaks is to stop using
MonetCompatActivityand initializeMonetCompatmyself using the application context.