A singleton that leaks
Context and object lifetimes
Analytics lives in the process and only needs application-level file access; it does not need a screen, window or Activity theme. The last MainActivity is finished while the process stays alive, and no further init occurs. Reference analysis shows Analytics → context → MainActivity.
Fix Analytics without changing the Activity. Repeated initialization during rotation replaces the stored reference, so this snippet alone does not prove that every old Activity accumulates. The problem is retaining the last finished screen.
Check: the singleton no longer retains that screen; reinitializing from another Activity still stores the process context; the solution is not used to create screen-bound dialogs. Context.getApplicationContext.
This saved draft exceeds the editor limit. Download it before resetting; the original is preserved.
The singleton outlives a particular Activity, so its strong reference retained the screen. The input here is a real Activity; applicationContext refers to the Application of its process. The fix changes the reference that is retained. Context contract.
This removes the specified retention path, not every possible leak: a callback or another global reference can still retain an Activity. Screen/window/theme operations need an appropriate screen context and are outside this exercise. The API was reviewed; this example was not run on Android.