Loading core/java/android/text/SpanSet.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.text; package android.text; import java.lang.reflect.Array; import java.lang.reflect.Array; import java.util.Arrays; /** /** * A cached set of spans. Caches the result of {@link Spanned#getSpans(int, int, Class)} and then * A cached set of spans. Caches the result of {@link Spanned#getSpans(int, int, Class)} and then Loading Loading @@ -54,6 +55,7 @@ public class SpanSet<E> { spanFlags = new int[length]; spanFlags = new int[length]; } } int prevNumberOfSpans = numberOfSpans; numberOfSpans = 0; numberOfSpans = 0; for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) { final E span = allSpans[i]; final E span = allSpans[i]; Loading @@ -71,6 +73,12 @@ public class SpanSet<E> { numberOfSpans++; numberOfSpans++; } } // cleanup extra spans left over from previous init() call if (numberOfSpans < prevNumberOfSpans) { // prevNumberofSpans was > 0, therefore spans != null Arrays.fill(spans, numberOfSpans, prevNumberOfSpans, null); } } } /** /** Loading Loading @@ -103,9 +111,8 @@ public class SpanSet<E> { * Removes all internal references to the spans to avoid memory leaks. * Removes all internal references to the spans to avoid memory leaks. */ */ public void recycle() { public void recycle() { // The spans array is guaranteed to be not null when numberOfSpans is > 0 if (spans != null) { for (int i = 0; i < numberOfSpans; i++) { Arrays.fill(spans, 0, numberOfSpans, null); spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled } } } } } } Loading
core/java/android/text/SpanSet.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.text; package android.text; import java.lang.reflect.Array; import java.lang.reflect.Array; import java.util.Arrays; /** /** * A cached set of spans. Caches the result of {@link Spanned#getSpans(int, int, Class)} and then * A cached set of spans. Caches the result of {@link Spanned#getSpans(int, int, Class)} and then Loading Loading @@ -54,6 +55,7 @@ public class SpanSet<E> { spanFlags = new int[length]; spanFlags = new int[length]; } } int prevNumberOfSpans = numberOfSpans; numberOfSpans = 0; numberOfSpans = 0; for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) { final E span = allSpans[i]; final E span = allSpans[i]; Loading @@ -71,6 +73,12 @@ public class SpanSet<E> { numberOfSpans++; numberOfSpans++; } } // cleanup extra spans left over from previous init() call if (numberOfSpans < prevNumberOfSpans) { // prevNumberofSpans was > 0, therefore spans != null Arrays.fill(spans, numberOfSpans, prevNumberOfSpans, null); } } } /** /** Loading Loading @@ -103,9 +111,8 @@ public class SpanSet<E> { * Removes all internal references to the spans to avoid memory leaks. * Removes all internal references to the spans to avoid memory leaks. */ */ public void recycle() { public void recycle() { // The spans array is guaranteed to be not null when numberOfSpans is > 0 if (spans != null) { for (int i = 0; i < numberOfSpans; i++) { Arrays.fill(spans, 0, numberOfSpans, null); spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled } } } } } }