I have service which will show an activity at particular point of time, after that activity on every 13th time i am showing an admob interstitial ads. My application's RAM usage is increasing by 20MB when the interstitial ad is shown and after that it is not getting garbage collected. On the next 13th time when another interstitial ads is shown there is no increase in the service memory.
My code for showing ads :
public void loadAndShowInterstitialAd() {
interstitial = new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId(AD_UNIT_ID);
final AdRequest adRequest = new AdRequest.Builder()
.build();
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
interstitial.loadAd(adRequest);
return true;
}
});
if (handler != null) {
handler.sendEmptyMessageDelayed(0, 200);
}
interstitial.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
I have tried few solutions in the following stack overflow questions, but nothing worked for me.