summaryrefslogtreecommitdiff
path: root/core/java/android/text/TextLine.java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-12-12 14:03:40 -0800
committerGilles Debunne <debunne@google.com>2011-12-12 14:03:40 -0800
commitc3fb7a11ad72c5e51ff93e1ad6958f843af0d5b1 (patch)
treeb25b9d0dd4a5eb7651723640b76c7baf44f5c5b1 /core/java/android/text/TextLine.java
parentcaf4ead320499cc9a7a2e3eb17beaaf92b391212 (diff)
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
Diffstat (limited to 'core/java/android/text/TextLine.java')
-rw-r--r--core/java/android/text/TextLine.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index b3df8ff5fbbc..303a30e13df7 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -102,6 +102,11 @@ class TextLine {
tl.mText = null;
tl.mPaint = null;
tl.mDirections = null;
+
+ tl.mMetricAffectingSpanSpanSet.recycle();
+ tl.mCharacterStyleSpanSet.recycle();
+ tl.mReplacementSpanSpanSet.recycle();
+
synchronized(sCached) {
for (int i = 0; i < sCached.length; ++i) {
if (sCached[i] == null) {
@@ -919,6 +924,12 @@ class TextLine {
}
return limit;
}
+
+ public void recycle() {
+ for (int i = 0; i < numberOfSpans; i++) {
+ spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled
+ }
+ }
}
/**