Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I believe that when the LRUCache evicts an image to make room for another one, the memory is not being freed.</p> </blockquote> <p>It won't be, until the <code>Bitmap</code> is recycled or garbage-collected.</p> <blockquote> <p>A quick google search reveals that this is happening because the image which is displaying has been recycled.</p> </blockquote> <p>Which is why you should not be recycling there.</p> <blockquote> <p>Why are recycled images still in the LRUCache if I'm only recycling them after they've been removed?</p> </blockquote> <p>Presumably, they are not in the <code>LRUCache</code>. They are in an <code>ImageView</code> or something else that is still using the <code>Bitmap</code>.</p> <blockquote> <p>What is the alternative for implementing a cache?</p> </blockquote> <p>For the sake of argument, let's assume you are using the <code>Bitmap</code> objects in <code>ImageView</code> widgets, such as in rows of a <code>ListView</code>.</p> <p>When you are done with a <code>Bitmap</code> (e.g., row in a <code>ListView</code> is recycled), you check to see if it is still in the cache. If it is, you leave it alone. If it is not, you <code>recycle()</code> it.</p> <p>The cache is simply letting you know which <code>Bitmap</code> objects are worth holding onto. The cache has no way of knowing if the <code>Bitmap</code> is still being used somewhere.</p> <p>BTW, if you are on API Level 11+, consider using <a href="http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inBitmap" rel="noreferrer"><code>inBitmap</code></a>. <code>OutOMemoryErrors</code> are triggered when an allocation cannot be fulfilled. Last I checked, Android does not have a compacting garbage collector, so you can get an <code>OutOfMemoryError</code> due to fragmentation (want to allocate something bigger than the biggest single available block).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload