linkedin / Spyglass

A library for mentions on Android
Apache License 2.0
387 stars 128 forks source link

Fix memory leak when saving MentionsEditText state #133

Closed lu16j closed 1 year ago

lu16j commented 1 year ago

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.

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

nhibner commented 1 year ago

Thanks!

rishiraj88 commented 1 year ago

Thanks, @lu16j , for smart fix.