title: Memory leak in android.os.Message and/or Handler.removeCallback?
body: <p>I have an activity that looks like the following:</p>
  
  <pre><code>class MyActivity extends Activity {
      Runnable refreshTimer = new Runnable() {
          public void run() {
              refresh();
          }
      };
  
      protected onCreate(...) {
          handler.postAtTime(refreshTimer, ...);
      }
  
      protected onDestroy() {
          handler.removeCallbacks(refreshTimer);
      }
  
      protected void refresh() { ... }
  }
  </code></pre>
  
  <p>After onDestroy is called, there are still messages in the activity's MessageQueue that contain references to MyActivity$0 (the refresh Runnable) for some reason.  Because MyActivity$0 has an implicit reference to MyActivity, this causes a memory leak of the MyActivity context.</p>
  
  <p>The result of merge_shortest_paths for android.app.Activity excluding phantom,soft,weak,etc references using Eclipse Memory Analyzer Tool:
  <img src="https://i.stack.imgur.com/EI2Aw.png" alt="enter image description here"></p>
  
  <p>(The source code above is a simplification of the actual object relationship displayed in the MAT dump)</p>
  
  <p>Shouldn't calling removeCallbacks remove any references to the runnable objects from the Queue? Why am I leaking contexts?</p>