title: Android AdMob causes memory leak?
body: <p>I've integrated AdMob v4.1.0 into my application and it seems to have caused a huge memory leak (pretty sure that it already happened on 4.0.4).</p>
  
  <p>In order to isolate the problem I created a new project with a blank linear layout and added the AdView to it (this is actually a copy&amp;paste from the sample code provided by AdMob). See my main.xml, MainActivity.java and manifest content:</p>
  
  <p>main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:id="@+id/linearLayout"&gt;
  &lt;TextView  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity.java:</p>
  
  <pre><code>package AdsTry.main;
  
  import com.google.ads.AdRequest;
  import com.google.ads.AdSize;
  import com.google.ads.AdView;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.LinearLayout;
  
  public class MainActivity extends Activity {
  
      private final int AD_VIEW_ID = 1000000; 
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
           // Lookup R.layout.main
          LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
  
          // Create the adView
          // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
          AdView adView = new AdView(this, AdSize.BANNER, "MY_BANNER_UNIT_ID");
          adView.setId(AD_VIEW_ID);
  
          // Add the adView to it
          layout.addView(adView);
  
          // Initiate a generic request to load it with an ad
          AdRequest request = new AdRequest();
  
          adView.loadAd(request);           
      }
  
      @Override
      protected void onPause() {
          Log.i("AdsTry", "onPause");
  
          getAdView().stopLoading();
  
          super.onPause();
      }
  
      @Override
      protected void onDestroy() {
          Log.i("AdsTry", "onDestroy");
  
          getAdView().destroy();
  
          super.onDestroy();
      }
  
      private AdView getAdView()
      {
          return (AdView) findViewById(AD_VIEW_ID);
      }
  }
  </code></pre>
  
  <p>manifest:</p>
  
  <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:name=".MainActivity"
                android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;!-- AdMobActivity definition --&gt;
      &lt;activity android:name="com.google.ads.AdActivity"
          android:configChanges="orientation|keyboard|keyboardHidden" /&gt;
  &lt;/application&gt;
  
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  </code></pre>
  
  <p>And that's all the code I have.</p>
  
  <p>Now, when running this application, I can see that both onPause and onDestory are called and the Activity is terminated, BUT the problem is that it will never be available for the GC since it causes the InputMethodManager to hold a reference to the Activity (See image taken from HPROF output after the activity was destroyed):
  <img src="https://i.stack.imgur.com/AoSQN.jpg" alt="MainActivity Merge shortest path to GC Roots"></p>
  
  <p>Once I remove the AdView-related code (and again, this is the ONLY code of this application) the problem goes away:
  <img src="https://i.stack.imgur.com/ynZ3N.jpg" alt="Same HPROF output without using AdView"></p>
  
  <p>EDIT:
  Also tried removing ALL the code from onCreate and updated the main.xml to contain the following (still get the same result):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/linearLayout"&gt;
      &lt;TextView  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/hello"
      /&gt;
      &lt;com.google.ads.AdView
      android:id="@+id/Ad"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      ads:adUnitId="MY_ID"
      ads:adSize="BANNER"
      ads:loadAdOnCreate="true"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Any ideas ????</p>