Skip to content

Commit a1277de

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "Prevent a memory leak in TextLine." into ics-mr1
2 parents 1fb9049 + c3fb7a1 commit a1277de

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)