AdView causes memory leak

I'm using AdView and LeakCanary. Fragment that hosts adView call adView.destroy() in onDestroy, but LeakCanary shows that Activity that hosts this fragment is leaked by com.google.android.gms.common.api.a.a.a.i . Heap dump also shows that there are memory leak. When I remove AdView.loadAd() and not loading Ad in fragment - there is no leak. Any thoughts or suggestions ? Thanks.


Same problem, AdView have an internal variable (strong reference) holding onto the context, which is my Activity, causing a leak of the Activity instance.

My dependency is com.google.android.gms:play-services-ads:8.3.0

A workaround is to supply the Application Context when creating the AdView instance.

AdView adview = new AdView(getApplicationContext());

Memory Leak: AdMob webviews cause activities to leak, In the next release, we will have an AdView.destroy() method that you can call in Activity.onDestroy(). I believe should fix the leak. Thanks, -Tim. - show quoted  One way to fix this problem is to create one single instance of adview using your base activity of your application. Add this adview to any activity you want, but remember to remove it in the activities on destroy method. This way the adview only leaks the base activity, which you almost never should have more than one instance of. Example:


PublisherAdView leaking Activity reference, I feel like I must be wrong - but am seeing issues where PublisherAdView is causing memory leaks. I am seeing this across all devices, Nexus 6, Nexus 9, Moto  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). 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&paste from the sample code provided by AdMob).


In my case, it was caused by using MobileAds initialization code with this in a lambda scope. After changing this to applicationContext, it was fixed.

Before:

MobileAds.initialize(this, "ca-app-pub-0000000000000000~0000000000")

After:

MobileAds.initialize(applicationContext, "ca-app-pub-0000000000000000~0000000000")

Leak caused by Adview · Issue #403 · square/leakcanary · GitHub, Memory leak occurs when I leave the application or when i rotate the screen, regardless of the number of rotation that I do, I leak just the first  In your case you are destroying AdView in onDestroy (After onDestroyView) so it is a leak. Because AdView is still there after Fragment View is destroyed. An Activity has NO onDestroyView method, view is destroyed in onDestroy in Activity. So there we clear objects in onDestroy. 2. Remove AdView from View programmatically.


Android AdMob causes memory leak?, 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  Memory leak occurs when I leave the application or when i rotate the screen, regardless of the number of rotation that I do, I leak just the first activity. I'm using AdView from google play services : com.google.android.gms:play-services-ads:8.4.0. Here is the full trace : In com.myapp:1.0:1. com.myapp.MainActivity has leaked:


Admob Memory Leak - avoiding by using empty activity, You could start a service as your app is closing to do this. This would prevent data from getting really big due to the memory leak. Nasty way to address it, but I​  Memory leaks are sneakily bad creatures. It's easy to ignore them for a very long time, while they slowly destroy the application. With memory leaks, your memory consumption grows, creating GC pressure and performance problems. Finally, the program will just crash on an out-of-memory exception.


google.android.gms.ads causing memory leaks : androiddev, I've found that the root cause is the AdMob AdView keeping references to old AdMob causes memory leak? and the sublinks in the comments/answers. Memory leak. In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.


Admob Memory Leak - avoiding by using empty activity, causing memory leaks. This is with the latest version, I am using PublisherAdView and the leaks have the same log as this report from 2015. Consequences. A memory leak reduces the performance of the computer by reducing the amount of available memory. Eventually, in the worst case, too much of the available memory may become allocated and all or part of the system or device stops working correctly, the application fails, or the system slows down vastly due to thrashing.