I followed "Avoiding Memory Leaks" article from here.
However the proposed solution does not solve the leak problem. I tested this with android emulator on Windows XP (SDK 2.3.1). I dumped the heap and checked the main activity is still in the heap (I used MAT)
Here's what I did:
- create HelloWorld app with HelloWorldActivity (it has no child views)
- run Emulator and launch HelloWorld app.
- close it by clicking back-key.
- Cause gc in DDMS and dump heap <-- Here I found HelloWorldActivity instance.
- 'Path to GC Roots' from it shows the following path.
HelloWorldActivity <- PhoneWindow$DecorView <- InputMethodManager
InputMethodManager is a singleton and three references to DecorView which references HelloWorldActivity.
I can't understand why InputMethodManager still references DecorView instance even after the activity is destroyed.
Is there any way to make sure that the main activity is destroyed and GC-able after closing it?