I have a test project which demonstrates a memory leak caused by Admob 4.1.1.
The basic scenario is I have two activities and I switch back and forth between the main and the sub activity several times. I then switch to DDMS and force a few GCs. Then dump the HPROF and look at the historgram filtered by com.test* to see how many instances of the main and sub activity there are. My screenshots of the histogram are attached:
A leak!
I then commented out the ads in the xml and reran and there were no leaks:
No leak now
I have found some relevant posts to Admob leaks such as here: Android AdMob causes memory leak?
Here is a list of things I have tried to resolve the issue:
- Wait some amount of time and then force gc
- Do not load the ad in oncreate but spawn a thread to wait then load it
- Tried a previous version of Admob (the one not written by Google)
- Called adView.destroy() in the onDestroy() activity's method
- The unbinding from this link
Obviously none of these things helped.
Here is the test project I wrote:
(Be sure to set your own publisher id when you run the test project)
download test leak android project
If it makes a difference I'm tesing on my SGS2 with Cyanogenmod ROM.
Does this happen for other people when they run this project?
Does anyone know the cause a fix or a workaround?
Thanks