I check the memory, trying to find possible memory leaks through hprof dumps.
I find that sometimes, when I leave the activity through the back button (which would complete the action), the activity will still be remembered, but it will have only one GC root, which does not seem very βstrongβ though.
This is my activity stream / the way I click and test:
A, B, C - actions.
1) A β B β (back) A
2) dump hprof with the following result:
B is still in memory , the only elements in the GC root of activity B are:
com.myapp.android.activity.directory.B
(The theme "main" seems to be a UI thread)
continue from A:
3) A β C β (back) A
4) dump hprof with the following result (as expected):
B is no longer in memory , C is no longer in memory, but only A
Now my question is: where does this PhoneLayoutInflater come from / why does it stay in memory when I return from B to A, but it will disappear after switching to C and return to A.
Obviously, PhoneLayoutInflater is designed to inflate ideas, I know about this purpose. I just donβt understand why it will be stored in memory through the GC root from the main user interface thread.
When I check the GC roots from the above
[local variable] java.lang.Thread [Thread] "main
he will have the following:
- mUiThread of com.myapp.android.activity.main. A [Stack Local]
- ....
- this $ 0 of android.view.inputmethod.InputMethodManager $ ControlledInputConnectionWrapper [JNI Global]
What I call actions B and C from A is done using regular startActivity(intent)
Why is the main thread of user interface A somehow connected and refers to activity B?