title: Android - Bitmap cache takes a lot of memory
body: <p>I'm new to all the memory management subject, so there are a lot of things I don't understand.<br>
  I'm trying to cache an image in my app, but I'm having troubles with its memory consumption:</p>
  
  <p>All of the Bitmap Chaching code is pretty much copy-pasted from here: <a href="http://developer.android.com/training/displaying-bitmaps/index.html">http://developer.android.com/training/displaying-bitmaps/index.html</a></p>
  
  <p>I debugged the code and checked the heap size in the DDMS view in eclipse, and there is about 15mb jump after these code lines:</p>
  
  <pre><code>        options.inJustDecodeBounds = false;
          return BitmapFactory.decodeResource(res, resId, options);
  </code></pre>
  
  <p>in the "decodeSampledBitmapFromResource" method.</p>
  
  <p>The image is 1024x800, 75kb jpg file. According to what I've already seen on the internet, the amount of memory this image is supposed to take is about 1024*800*4(Bytes per pixel)=3.125mb</p>
  
  <p>All of the threads regarding this subject don't say why it's taking much more memory than it should. Is there a way to cache one image with a reasonable amount of memory?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I tried using the decodeFile method suggested on @ArshadParwez's answer below. Using this method, after the BitmapFactory.decodeStream method the memory is increased by only 3.5mb - problem solved, sort of, but I want to cache bitmaps directly from the resource.</p>
  
  <p>I noticed that during the decodeResource method there are 2 memory "jumps" - one of about 3.5mb - which is reasonable, and another strange one of 14mb. What are those 14mb used for and why does this happen?</p>