Again - java.lang.OutOfMemoryError: bitmap size exceeds VM budget
<p>I am getting the 'java.lang.OutOfMemoryError: bitmap size exceeds VM budget' error... What I am doing is that I download ~50 images from server and store them in the memory.</p>

<p>When I first saw this problem I optimize our images to download thumbnails only (50 JPEGS, ~12kB each, size 160x240px) and I start releasing them by calling Bitmap.recycle() as soon as I do not need them. Everything is working on newer phones, where the process can get 32MB, but on older phones with 16MB max not.</p>

<p>So my questions are:</p>

<ul>
<li><p>Is it correct that all processes are limited to 32MB or less on older phones (i.e. the memory the <strong>Runtime.getRuntime().maxMemory()</strong> call returns) and this memory is for the Dalvik, framework, application and data?</p></li>
<li><p>Can we use more memory in application then amount returned by <strong>Runtime.getRuntime().maxMemory()</strong> ?</p></li>
<li><p>How I should optimize the images - they are anyway pretty small now... Should I start swapping them to internal flash/SD? I am keeping them in memory as long as they are shown in the <strong>GridView</strong>...</p></li>
</ul>

<p>I appreciate any help - I went through the similar thread here and done what I have seen there... but still it is not enough...</p>

<hr>

<p><em>Edit update</em></p>

<p>I added those comments after <code>weakwire</code> answer.</p>

<p>•   In my case I download ~50 images and store all of them in Bitmap objects in memory. See below why I am doing that.</p>

<p>•   How much memory occupies the image in the <strong>Bitmap</strong> object? Is it there in raw format means that if image is <code>160x240x24bpp</code> it occupies <code>~115 kB</code> in memory, so <code>50 images are ~6MB</code>? <strong>Is that correct?</strong></p>

<p>•   I have also read that images are not part of my process heap, but they are counted, so using the <strong>maxMemory(), totalMemory(), freeMemory()</strong> cannot really help. <strong>Is that correct?</strong></p>

<p>•   My application UI has complete custom graphics (60 png files, many of them in draw9pacth format)</p>

<p>•   I have no problem on 24/32 MB devices, I have problem only on 16 MB devices</p>

<p>•   As soon as I download all 50 images and store them into memory I show them in the 2 columns width <strong>GridView</strong>. I think for this I need to keep all images on the heap (saving to internal flash I think is not solution there). <strong>Is that correct assumption?</strong></p>

<p>•   When I initialize the application and the UI is loaded I can see that I have 448kB free memory of 5459kB allocated of the whole 16384kB budget. I assume I cannot really use the whole 16384kB + if I understand it correctly I cannot really see from maxMemory(), totalMemory(), freeMemory() how much images that are already loaded occupy, since the dalvik-vm does not 'see' this heap. Assuming that ~2M are already used and I can use up to ~14MB I have 5.5MB left, so I can easily with 50 images in the memory run into OOM problems… <strong>Is that correct computation?</strong></p>

<p>I WILL definitely go over the suggested video – it looks nice – but <code>weakwire</code>, please try to answer me my questions…  Thanks for that and for your time!</p>
