title: System.gc() causing slowdown from the second start of Activity
body: <p>I am experiencing a very strange phenomenon (test device: HTC Desire HD, Android 2.3.5). I know that <code>System.gc()</code> is needless and discouraged, and I don't try to suggest otherwise, but the point is that <strong>it shouldn't cause issues either</strong> (i.e. it should be useless <em>at most</em>).</p>
  
  <p>I have an application which contains a <code>GLSurfaceView</code> in its view hierarchy. The <code>GLSurfaceView</code> is instantiated and added in the <code>Activity.onCreate()</code>. Normally, the application works like this:</p>
  
  <ol>
  <li>User starts the app and goes to mainmenu</li>
  <li>User chooses a mainmenu item which sets the <code>GLSurfaceView</code> to <code>View.VISIBLE</code></li>
  <li>User plays with the in-built game on <code>GLSurfaceView</code></li>
  <li>User goes to mainmenu and exits the activity (=> <code>Activity.finish()</code> is called)</li>
  </ol>
  
  <p>My <code>Activity.onPause()</code> looks like this:</p>
  
  <pre><code>mGameThread.pause(); // gameThread is my custom thread class for the in-built game
  mGLView.onPause(); // pause the renderer thread
  </code></pre>
  
  <p>So far so good, everything works fine. However, issues appear after I add the following code to <code>onPause()</code> (for the case when the user exits the game from the mainmenu):</p>
  
  <pre><code>mGameThread.pause(); // gameThread is my custom thread class for the in-built game
  mGLView.onPause(); // pause the renderer thread    
  if (isFinishing()) {
      System.gc();
  }
  </code></pre>
  
  <p>In details: if the <code>Activity</code> is started <em>for the first time</em> (= i.e. the app process didn't exist before), everything works fine. However, <em>starting from the 2nd start</em> of the activity (= after the first exit from the mainmenu, i.e. after the first <code>Activity.finish()</code>), <strong>the framerate of GLSurfaceView is reduced by 40-50%</strong>, the in-built game becomes slow.</p>
  
  <p>If I remove the <code>System.gc()</code> call, the problem disappears. Moreover, if I do the following, it also gets rid of the problem:</p>
  
  <pre><code>mGameThread.pause(); // gameThread is my custom thread class for the in-built game
  mGLView.onPause(); // pause the renderer thread
  if (isFinishing()) {
      // 1. get layout root of View hierarchy
  
      // 2. recursively remove (detach) all Views
  
      // 3. call GC
      System.gc();
  }
  </code></pre>
  
  <p>I didn't add concrete code because it's complex, so I used comments. If I just detach the <code>GLSurfaceView</code> via <code>removeView()</code>, it is not enough. The entire view hierarchy needs to be cleared.</p>
  
  <p>Note that I couldn't find any memory leaks (no Activity leak via drawables/statics etc.). Moreover, of course, the gameThread properly exits when the app is closed (I just didn't include its source code).</p>
  
  <p>Any ideas, guesses? Apparently, <code>System.gc()</code> seems to cause some issues for the Activity/layout destroying mechanism of Android. Again, as I said, if I remove <code>System.gc()</code>, the problem disappears.</p>