mur*_*rkr 5 memory android memory-leaks spannablestring
所以,....
我有这个代码(onStart):
ss = new SpannableString(getString(R.string.legal_user_acceptance_disclaimer));
ss.setSpan(clickableSpanTermsOfUse, 32, 44, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
它泄漏了父级- Activity(这些行在里面)。
如果我只改变数字:
ss.setSpan(clickableSpanTermsOfUse, 49, 63, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
泄漏消失。
clickableSpanTermsOfUse (memory leak is the same with a normal ClickableSpan):
clickableSpanTermsOfUse = new NoRefCopySpan() {
@Override
public void onClick(View textView) {
startActivity(new Intent(ChooseLoginRegistrationActivity.this, PrivacyStatement.class));//, TermsOfUse.class));
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
public class NoRefCopySpan extends ClickableSpan implements NoCopySpan {
@Override
public void onClick(@NonNull View widget) { }
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
}
Run Code Online (Sandbox Code Playgroud)
I tried around a lot, using SpannableStringBuilder instead of SpannableString, hooking somewhere else into the lifecycle, manually setting all values to null, the only thing that makes a difference is, WHERE I put the ClickableSpan.
What's going on here na dhow can I get rid of the memory leak?