title: Heap not expanding on Genymotion emulator
body: <p>While resizing large bitmaps for faster image upload to a server I occasionally ran into OutOfMemoryErrors. 
  To prevent this I calculate the required amount of memory and check if it exceeds Runtime.getRuntime().maxMemory() before trying to scale an image.</p>
  
  <p>However, I still run into OOM errors even though the image should fit on the heap easily.</p>
  
  <p>The emulated device (Galaxy SII API 16) gives me a max memory of 67108864 bytes using the above method.</p>
  
  <p>In the following snippet, the heap size is 43975K and only &lt; 15K of that memory is in use. For my ~31K allocation the heap should grow automatically to about 45K which is still not even close to the maximum size of 64 MiB.
  But as you can see, instead of expanding the heap, the dalvik vm runs out of memory.</p>
  
  <pre><code>10-13 20:35:57.223: D/dalvikvm(1201): GC_FOR_ALLOC freed 505K, 67% free 14692K/43975K, paused 31ms, total 31ms
  10-13 20:35:57.223: I/dalvikvm-heap(1201): Forcing collection of SoftReferences for 31961100-byte allocation
  10-13 20:35:57.251: D/dalvikvm(1201): GC_BEFORE_OOM freed 2K, 67% free 14689K/43975K, paused 29ms, total 29ms
  10-13 20:35:57.251: E/dalvikvm-heap(1201): Out of memory on a 31961100-byte allocation.
  </code></pre>
  
  <p>I wonder if this can happen on a real device too or if this could be a genymotion bug. </p>
  
  <p>Is the heap guaranteed to expand up to maxMemory()? The JavaDoc for Runtime.getRuntime().freeMemory() says it "may" expand, whatever that means.</p>
  
  <p>I just need a realiable way to calculate the amount of memory I can use, this is how I did it, please correct me if I'm wrong:</p>
  
  <pre><code>long maxMemory = Runtime.getRuntime().maxMemory();
  long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
  long availableMemory = maxMemory - usedMemory;
  </code></pre>
  
  <p>This call causes the OutOfMemoryError:</p>
  
  <pre><code>// outOptions has an appropriate inSampleSize
  BitmapFactory.decodeStream(inputStream, null, outOptions);
  </code></pre>