diff options
author | Amith Yamasani <yamasani@google.com> | 2011-07-25 16:27:09 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2011-08-12 14:40:43 -0700 |
commit | 352c01e2133b71918fa1cb2783a0a10e56117775 (patch) | |
tree | e706d2db89aa0678db5594f7c8b8399b0b93469c | |
parent | 6e97ed2127bdda72fee739fe9d28011d52155b9c (diff) | |
download | frameworks_base-352c01e2133b71918fa1cb2783a0a10e56117775.zip frameworks_base-352c01e2133b71918fa1cb2783a0a10e56117775.tar.gz frameworks_base-352c01e2133b71918fa1cb2783a0a10e56117775.tar.bz2 |
Use a weakreference to prevent the static variable from holding an Activity.
Bug: 5057764
Change-Id: If734e3ef4928b21a5e31e0ad50c97da287c3c116
-rw-r--r-- | core/java/android/text/DynamicLayout.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java index 2c78679..4f42659 100644 --- a/core/java/android/text/DynamicLayout.java +++ b/core/java/android/text/DynamicLayout.java @@ -268,10 +268,11 @@ extends Layout // generate new layout for affected text StaticLayout reflowed; - + WeakReference<StaticLayout> layoutRef; synchronized (sLock) { - reflowed = sStaticLayout; - sStaticLayout = null; + layoutRef = sStaticLayoutRef; + reflowed = sStaticLayoutRef != null ? sStaticLayoutRef.get() : null; + sStaticLayoutRef = null; } if (reflowed == null) { @@ -358,8 +359,12 @@ extends Layout } synchronized (sLock) { - sStaticLayout = reflowed; reflowed.finish(); + if (layoutRef == null || layoutRef.get() != reflowed) { + sStaticLayoutRef = new WeakReference<StaticLayout>(reflowed); + } else { + sStaticLayoutRef = layoutRef; + } } } @@ -488,7 +493,8 @@ extends Layout private int mTopPadding, mBottomPadding; - private static StaticLayout sStaticLayout = new StaticLayout(true); + private static WeakReference<StaticLayout> sStaticLayoutRef = new WeakReference<StaticLayout>( + new StaticLayout(true)); private static final Object[] sLock = new Object[0]; private static final int START = 0; |