com.android.internal.policy.impl.PhoneLayoutInflater sometimes remaining in memory (hprof dumps)
<p>I'm inspecting memory trying to find eventual memory leaks via hprof dumps.</p>

<p>I find that sometimes when I leave an activity via back button (which would finish the activity), the activity would still remain in memory but it would only have two GC root, which don't seem to be very 'strong' though.</p>

<p>This is my activity flow / the way I click and test:</p>

<p>A, B, C being activities.</p>

<p><strong>1) A -> B -> (back to) A</strong></p>

<p><strong>2) do a hprof dump</strong> with the following result:</p>

<p><em><strong>B is still in memory</em></strong>, the only elements in GC root of B activity are: </p>

<p>com.myapp.android.activity.directory.B</p>

<ul>
<li><p>mContext of <strong>com.android.internal.policy.impl.PhoneLayoutInflater</strong></p>

<ul>
<li><p>mLayoutInflater of android.app.ContextImpl [Stack Local]</p>

<ul>
<li>[local variable] of java.lang.Thread [Thread]  "main"</li>
</ul></li>
</ul></li>
<li><p>mOuterContext <strong>of android.app.ContextImpl [Stack Local]</strong></p>

<ul>
<li>[local variable] of java.lang.Thread [Thread]  "main"</li>
</ul></li>
</ul>

<p>(Thread "main" seems to be the UI thread)</p>

<p>continue from A:</p>

<p><strong>3) A -> C -> (back to) A</strong></p>

<p><strong>4) do a hprof dump</strong> with the following result (as expected):</p>

<p><strong>B is not in memory anymore</strong>, C is not in memory anymore, only A</p>

<p><strong>Now my question is:
where does this PhoneLayoutInflater come from / why does it remain in memory when I return from B to A, but it would be gone after went further on to C and return back to A.</strong></p>

<p>Obviously the PhoneLayoutInflater is for inflating views, I'm aware of it's purpose. I just don't see why it would be kept in memory via the GC root from the main UI thread.</p>

<p>When I check the GC roots of above listed </p>

<blockquote>
  <p>[local variable] of java.lang.Thread
  [Thread] "main</p>
</blockquote>

<p>it would have the following:</p>

<ul>
<li>mUiThread of com.myapp.android.activity.main.<strong>A</strong> [Stack Local]
<ul>
<li>....
<ul>
<li>this$0 of android.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper <strong>[JNI Global]</strong></li>
</ul></li>
</ul></li>
</ul>

<p>The way I call the activities B and C from A is via a regular <code>startActivity(intent)</code></p>

<p><strong>Why would the main UI thread of activity A somehow be related and referenced from activity B?</strong></p>
