title: Android deallocate Bitmaps going into "unknown" memory
body: <p>I'm making a sketching app, mostly for fun. But i've run into a problem.</p>
  
  <p>Within my app, the user can "flip" through sketches they've already drawn. These sketches are just 400x800 Bitmaps. But i'm constantly running into out of memory errors.</p>
  
  <p>Sketches are saved to SD as soon as the user flips away from them, and they are then deallocated with...</p>
  
  <pre><code>if(bitmap != null)
  {
  bitmap.recycle();
  bitmap = null;
  }
  </code></pre>
  
  <p>So, only one or two Bitmaps should be loaded into memory at any given time, before they are saved and deallocated. And with a few debug prints, i've determined that this is true (max. two bitmaps in memory at the same time). My problem is that after 14 loads/deallocations, the program crashes with an OutOfMemoryError. Always 14, no matter how long i wait between "flips".</p>
  
  <p>I've tried opening DDMS to see what the device's memory allocation is like. Strangely, every time an image is deallocated, memory goes to the "unknown" section, instead of the "free" section. This continues until there is only a sliver of "free" memory left, at which point the crash occurs (and the "unknown" memory goes to "free").</p>
  
  <p>After a lot of googling, i've found a few resources which say that bitmaps should be <a href="https://stackoverflow.com/questions/1945142/bitmaps-in-android">deallocated as expected</a>, and that <a href="http://dubroy.com/blog/google-io-memory-management-for-android-apps/" rel="nofollow noreferrer">Dalvik garbage collections always occur before an out of memory error</a>. And a few miscellaneous pages that suggested that ALL memory used by a Bitmap is deallocated upon GC (native and JVM heap alike)</p>
  
  <p>I should note, at this point, that i'm testing on two different phones. Motorola Droid X (stock image, Android 2.3.3), and Samsung Galaxy S3 (Cyanogenmod 9, Android 4.0.4). Both exhibit the exact same behavior. My android tools are up to date with all SDK versions, and i've checked a million times to make sure that nothing else in my code is doing any weird allocations (practically nothing is allocated after program startup).</p>
  
  <p><strong>So</strong>, how should i properly deallocate a Bitmap so that it is freed (not just "unknown"), and i can use the memory elsewhere?
  As a sort of supplemental question, what is this "unknown" memory pool, and what is it for?</p>
  
  <p>EDIT: Grammar and spelling, added some notes on platform.</p>