Life · 2 / 4

A singleton that leaks

Context and object lifetimes

Easyandroidmemory

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.

Your code
Solution