Skip to content

Commit c3fb7a1

Browse files
author
Gilles Debunne
committed
Prevent a memory leak in TextLine.
Bug 5740435 The new SpanSet cached objects should be recycled when the TextLine is recycled to prevent a reference to their span, which may lead to the entire activity. Change-Id: I4469e418a228bd71eb8be1d43ed86de49baba165
1 parent caf4ead commit c3fb7a1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

core/java/android/text/TextLine.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ static TextLine recycle(TextLine tl) {
102102
tl.mText = null;
103103
tl.mPaint = null;
104104
tl.mDirections = null;
105+
106+
tl.mMetricAffectingSpanSpanSet.recycle();
107+
tl.mCharacterStyleSpanSet.recycle();
108+
tl.mReplacementSpanSpanSet.recycle();
109+
105110
synchronized(sCached) {
106111
for (int i = 0; i < sCached.length; ++i) {
107112
if (sCached[i] == null) {
@@ -919,6 +924,12 @@ int getNextTransition(int start, int limit) {
919924
}
920925
return limit;
921926
}
927+
928+
public void recycle() {
929+
for (int i = 0; i < numberOfSpans; i++) {
930+
spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled
931+
}
932+
}
922933
}
923934

924935
/**

0 commit comments

Comments
 (0)