My Activity is still in the memory after running "finish()" and OnDestroy(). It is not garbage collected.
After days of analysis with Memory Profiler I have isolated the issue in the RewardedAd.
Basically, if I comment the entries in createAndLoadRewardedAd() method, where rewardedAd is initialized, the activity is properly destroyed:
private RewardedAd createAndLoadRewardedAd() {
if (1==1) return null; //IF THIS LINE IS COMMENTED, THERE WILL BE MEMORY LEAK!!!
RewardedAd rewardedAd = new RewardedAd(this,
getResources().getString(R.string.rewards_ad_unit_id));
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
@Override
public void onRewardedAdLoaded() {
// Ad successfully loaded.
}
@Override
public void onRewardedAdFailedToLoad(int errorCode) {
// Ad failed to load.
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
return rewardedAd;
}I have implemented rewardedAd as stated in the official documentation: https://developers.google.com/admob/android/rewarded-ads
Unfortunately, this document does not provide instructions to disable/destroy/nullify the related objects.
I'm setting rewardedAd to null in onDestroy, but this is not enough.
Hi Pablo,
You may send us your sample project via Google Drive or via any other filesharing service that you prefer. Don't forget to send the link via Reply privately to author.
Regards,
Ziv Yves Sanchez
Hi Pablo,
Unfortunately we did not receive your project. Could you try then by sending to mobileadstesting99@gmail.com?
My Activity is still in the memory after running "finish()" and OnDestroy(). It is not garbage collected.
After days of analysis with Memory Profiler I have isolated the issue in the RewardedAd.
Basically, if I comment the entries in createAndLoadRewardedAd() method, where rewardedAd is initialized, the activity is properly destroyed:
private RewardedAd createAndLoadRewardedAd() { if (1==1) return null; //IF THIS LINE IS COMMENTED, THERE WILL BE MEMORY LEAK!!! RewardedAd rewardedAd = new RewardedAd(this, getResources().getString(R.string.rewards_ad_unit_id)); RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() { @Override public void onRewardedAdLoaded() { // Ad successfully loaded. } @Override public void onRewardedAdFailedToLoad(int errorCode) { // Ad failed to load. } }; rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback); return rewardedAd; }I have implemented rewardedAd as stated in the official documentation: https://developers.google.com/admob/android/rewarded-ads
Unfortunately, this document does not provide instructions to disable/destroy/nullify the related objects.
I'm setting rewardedAd to null in onDestroy, but this is not enough.
|
||||||
Hi Everyone,
Thanks for your patience on this.
Please see updates from our team below:
"We retain the reference to the activity while the ad is loading. If the load completes or times out then the reference is no longer held and can be cleaned up, therefore resulting in no leak. That's why the leak is temporary. If you're using a lot of memory and loading ads is causing you to get out of memory crashes, then you would need to try to reduce overall memory usage by not loading as many ads at once or by using queues (to manage bitmap handling for example). The SDK needs reference to the activity while the load is occurring in order to avoid unexpected behavior which would manifest as other bugs."
Regards,