diff options
author | Adam Koch <akoch@google.com> | 2013-11-07 17:07:04 -0500 |
---|---|---|
committer | Adam Koch <akoch@google.com> | 2013-11-07 22:08:08 +0000 |
commit | 67257655a3a1921fa0837f5de34e9f5d3babc938 (patch) | |
tree | e52306fc60d6d391c85d0c468389a3d5c30d4c6f /docs/html/training | |
parent | 347b6fc9e3bbd15364a0d1be74bd6ed98a3a1bfe (diff) | |
download | frameworks_base-67257655a3a1921fa0837f5de34e9f5d3babc938.zip frameworks_base-67257655a3a1921fa0837f5de34e9f5d3babc938.tar.gz frameworks_base-67257655a3a1921fa0837f5de34e9f5d3babc938.tar.bz2 |
Bitmapfun Sample: Minor updates/fixes.
Change-Id: I6ac19a95a65ab5210f62d1f50d76f2b3e1b533ef
Diffstat (limited to 'docs/html/training')
-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(); } } } |