Google AdMob非页内广告导致内存泄露

时间:2014-10-28 07:52:07

标签: android memory-leaks admob

使用MAT和hprof转储文件,我发现当我旋转屏幕时,我的应用程序中有两个主要活动实例。注意包名已被编辑:)

enter image description here

这是MainActivity $ 1的传入对象

enter image description here

MainActivity $ 1的类引用

enter image description here

当我显示GC根的路径,不包括InterstitialAd类的弱引用时,我得到以下输出。

enter image description here

我在统治或根源方面的理解是作为我的对象的引用interstitialAd阻止了这种垃圾收集。我不确定ky或IQ是什么。

这是我的插页式广告实施。请注意,我的应用只有一项活动。 我将展示与InterstitialAd相关的部分,只是为了清晰简洁。 主要活动

private InterstitialAd interstitialAd;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad_unit_id));
        interstitialAd.setAdListener(new AdListener()
        {
            @Override
            public void onAdLoaded() 
            {
                if(isTheAppInFrontOfTheUser)
                {
                    interstitialAd.show();
                }


            }

            @Override
            public void onAdClosed() 
            {
                interstitialAd = null;
                SharedPreferences userPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                SharedPreferences.Editor editor = userPrefs.edit();
                editor.putLong("dateTimeOfLastInterstitialAd", System.currentTimeMillis());
                editor.commit();


            }
        });
}

这就是所谓的请求interstitialAd

public void showInterstitialAd()
    {

            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .build(); 
            interstitialAd.loadAd(adRequest);


    }

我的毁灭方法

@Override
    protected void onDestroy() 
    {
        interstitialAd = null;
        super.onDestroy();
    }

1 个答案:

答案 0 :(得分:0)

我只在您的日志中看到一个MainActivity实例。 0x41c7af8。另一个在哪里?

注意ACRA ErrorReporter持有对lastActivityCreated的WeakReference。