MentionsEditable is a SpannableStringBuilder, which may contain Spans such as TextWatcher which may contain references to Views. To avoid leaking the view tree, we should copy the MentionsEditable before saving it - this will not copy the TextWatchers to the new instance since they are NoCopySpans.
MentionsEditable
is aSpannableStringBuilder
, which may containSpan
s such asTextWatcher
which may contain references toView
s. To avoid leaking the view tree, we should copy theMentionsEditable
before saving it - this will not copy theTextWatcher
s to the new instance since they areNoCopySpan
s.This copying is also performed in the base
TextView
: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/widget/TextView.java;l=6215?q=TextView.java