diff options
author | Adam Koch <akoch@google.com> | 2013-11-12 11:57:20 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-11-12 11:57:20 -0800 |
commit | 1d64812a35350692e0a770dcf278fab45ff855c8 (patch) | |
tree | e4a261ba1262b0289e4a448d32beced601deea81 /docs/html | |
parent | 6f569bd971ef0248750888e6c4b118b0974111af (diff) | |
parent | c6a6539c27f1abe10948dfebcff1d1ac9712c7d3 (diff) | |
download | frameworks_base-1d64812a35350692e0a770dcf278fab45ff855c8.zip frameworks_base-1d64812a35350692e0a770dcf278fab45ff855c8.tar.gz frameworks_base-1d64812a35350692e0a770dcf278fab45ff855c8.tar.bz2 |
am c6a6539c: am e95c167c: Merge "Bitmapfun Sample: Minor updates/fixes." into klp-docs
* commit 'c6a6539c27f1abe10948dfebcff1d1ac9712c7d3':
Bitmapfun Sample: Minor updates/fixes.
Diffstat (limited to 'docs/html')
-rw-r--r-- | docs/html/training/displaying-bitmaps/manage-memory.jd | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/docs/html/training/displaying-bitmaps/manage-memory.jd b/docs/html/training/displaying-bitmaps/manage-memory.jd index 0e1279e..7f2b4c5 100644 --- a/docs/html/training/displaying-bitmaps/manage-memory.jd +++ b/docs/html/training/displaying-bitmaps/manage-memory.jd @@ -160,13 +160,14 @@ a soft reference to the bitmap is placed in a {@link java.util.HashSet}, for possible reuse later with {@link android.graphics.BitmapFactory.Options#inBitmap}: -<pre>HashSet<SoftReference<Bitmap>> mReusableBitmaps; +<pre>Set<SoftReference<Bitmap>> mReusableBitmaps; private LruCache<String, BitmapDrawable> mMemoryCache; -// If you're running on Honeycomb or newer, create -// a HashSet of references to reusable bitmaps. +// If you're running on Honeycomb or newer, create a +// synchronized HashSet of references to reusable bitmaps. if (Utils.hasHoneycomb()) { - mReusableBitmaps = new HashSet<SoftReference<Bitmap>>(); + mReusableBitmaps = + Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>()); } mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) { @@ -243,25 +244,27 @@ protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) { Bitmap bitmap = null; if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) { - final Iterator<SoftReference<Bitmap>> iterator - = mReusableBitmaps.iterator(); - Bitmap item; - - while (iterator.hasNext()) { - item = iterator.next().get(); - - if (null != item && item.isMutable()) { - // Check to see it the item can be used for inBitmap. - if (canUseForInBitmap(item, options)) { - bitmap = item; - - // Remove from reusable set so it can't be used again. + synchronized (mReusableBitmaps) { + final Iterator<SoftReference<Bitmap>> iterator + = mReusableBitmaps.iterator(); + Bitmap item; + + while (iterator.hasNext()) { + item = iterator.next().get(); + + if (null != item && item.isMutable()) { + // Check to see it the item can be used for inBitmap. + if (canUseForInBitmap(item, options)) { + bitmap = item; + + // Remove from reusable set so it can't be used again. + iterator.remove(); + break; + } + } else { + // Remove from the set if the reference has been cleared. iterator.remove(); - break; } - } else { - // Remove from the set if the reference has been cleared. - iterator.remove(); } } } |