We have Activities and Fragments leaking and have traced the cause back to what appears to be un-removed ChangeWatchers on TextViews.
Scenario: Activity A starts Activity B. B has a textPassword EditText field in its layout. Activity B finishes.
The HPROF dump shows that there is still one instance of Activity B. Its gcroot path is the following:
test.maa.LoginActivity
'- mContext android.widget.EditText
'- this$0 android.widget.TextView$ChangeWatcher
'- [1] java.lang.Object[13]
'- mSpans android.text.SpannableStringBuilder
'- mSource android.text.method.PasswordTransformationMethod$PasswordCharSequence
'- mText android.text.MeasuredText
'- mMeasured android.text.StaticLayout
'- sStaticLayout class android.text.DynamicLayout
This also happens if you Linkify.addLinks to a TextView.
Is there any way to clean up Activity B?
As far as I can tell, this appears to be a bug in Android related to the TextView ChangeWatcher and Linkify or Html.fromHtml spannable strings. I was able to work around the problem by calling setText(null)
in my activity's onDestroy(). There may be other workarounds that work as well, but I wasn't able to find any further information on the leak.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With