diff options
author | Romain Guy <romainguy@android.com> | 2015-04-08 07:38:58 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-08 07:38:58 +0000 |
commit | 492c836f831808bc306678c5e0948df8bffa106b (patch) | |
tree | 4d6d1ec18e55f37355feb1a3328df76249655aea /core | |
parent | 9054431af3f7de58b2769b63d863bdfa85c3bd1c (diff) | |
parent | 5b61a282255b5273f5194db73f3c88550dc11a57 (diff) | |
download | frameworks_base-492c836f831808bc306678c5e0948df8bffa106b.zip frameworks_base-492c836f831808bc306678c5e0948df8bffa106b.tar.gz frameworks_base-492c836f831808bc306678c5e0948df8bffa106b.tar.bz2 |
am 5b61a282: am e4d787b2: am 80e455e3: Merge "Prevent possible memory leak in SpanSet"
* commit '5b61a282255b5273f5194db73f3c88550dc11a57':
Prevent possible memory leak in SpanSet
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/text/SpanSet.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/core/java/android/text/SpanSet.java b/core/java/android/text/SpanSet.java index 3ca6033..00f1493 100644 --- a/core/java/android/text/SpanSet.java +++ b/core/java/android/text/SpanSet.java @@ -17,6 +17,7 @@ package android.text; 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 @@ -54,6 +55,7 @@ public class SpanSet<E> { spanFlags = new int[length]; } + int prevNumberOfSpans = numberOfSpans; numberOfSpans = 0; for (int i = 0; i < length; i++) { final E span = allSpans[i]; @@ -71,6 +73,12 @@ public class SpanSet<E> { 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); + } } /** @@ -103,9 +111,8 @@ public class SpanSet<E> { * Removes all internal references to the spans to avoid memory leaks. */ public void recycle() { - // The spans array is guaranteed to be not null when numberOfSpans is > 0 - for (int i = 0; i < numberOfSpans; i++) { - spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled + if (spans != null) { + Arrays.fill(spans, 0, numberOfSpans, null); } } } |