Memory leak in AdMob banner ads contributing to OutOfMemory exceptions

276 views
Skip to first unread message

Andrew Simpson

unread,
Jul 8, 2024, 5:12:47 AMJul 8
to Google Mobile Ads SDK Developers

After noticing our Android apps increased crash rate in Google Play Console, investigations lead to an unexpected number of OOM exceptions. This was mitigated almost completely when we disabled AdMob ads.

After some investigations, we added code to capture unhandled exceptions locally, and ran our apps until we received an OOM. I've captured the heapdump from there and converted the hprof file. The only thing needed to reproduce this is to enable AdMob ads, and display banner ads, having them rotate as expected. (We are using AdMob via AppLovin, but these issues of OOM crashes disappear when we disable AdMob, and investigations appear to lead directly to the AdMob library, as i'll explain below).

This is from the MAT tool leak suspects report:
```
One instance of com.google.android.gms.ads.nonagon.signalgeneration.k loaded by dalvik.system.DelegateLastClassLoader @ 0x13150b10 occupies 41,583,280 (14.37%) bytes. The memory is accumulated in one instance of java.lang.Object[], loaded by <system class loader>, which occupies 37,175,312 (12.85%) bytes.

Thread m.ahy @ 0x12e8d208 has a local variable or reference to class m.ahy @ 0x131e9870 which is on the shortest path to java.lang.Object[16384] @ 0x239115e8. The thread m.ahy @ 0x12e8d208 keeps local variables with total size 528 (0.00%) bytes.

Keywords

  • com.google.android.gms.ads.nonagon.signalgeneration.k
  • dalvik.system.DelegateLastClassLoader
  • java.lang.Object[]```

To me, it looks like the `ArrayDeque` is being excessively used somewhere inside `signalgeneration`, keep around forever and never cleared, constantly growing over time, eventually leading to OOM crashes if the app lives long enough.

Please fix this leak, as it is preventing me from using google AdMob ads in my app, because we were starting to approach the "Bad Behavior" crash threshold on Google Play due the OOM exceptions, and AdMob is definitely contributing here.

Please let me know if there is any other diagnostic information i can provide to help fix this issue.

Screenshot 2024-07-05 193129.png

Mobile Ads SDK Forum Advisor

unread,
Jul 8, 2024, 9:12:27 AMJul 8
to andrew.p...@gmail.com, google-adm...@googlegroups.com

Hi Andrew,

Thank you for contacting the Mobile Ads SDK Support team. 

Could you confirm whether the mentioned issue is reproducible in our Google sample project? If yes, kindly share the below information privately so we can review it and try to replicate the problem. After doing so, we will be better equipped to offer a solution. 

  • app ID
  • ad unit ID
  • Sample project reproducing the issue
  • Steps to replicate the issue
  • The full stack trace
  • Frequency of crashes.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files via reply to author option or by performing the following steps:

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002tJlLlQAK&entry.80707362=00245510

2. Fill out all fields and attach your file(s).

3. Please reply on this thread when you have uploaded your file(s). Please do not share this link.

This message is in relation to case "ref:!00D1U01174p.!5004Q02tJlLl:ref" (ADR-00245510)

Thanks,
 
Google Logo Mobile Ads SDK Team


sxdev

unread,
Jul 10, 2024, 1:51:52 PMJul 10
to Google Mobile Ads SDK Developers

This problem is reproducible with the Google sample project.  To reproduce it:

1 - Install the java BannerExample sample project.
2 - Change admob ids and use a banner ID that has auto-refresh on.
3 - Run project.

On each refresh, the app stores a pair of banner ad items with no apparent upper bound.  On the simulator this is about 2x250K memory growth per ad refresh.

Using profiler, sorted by Shallow Size, you will see the item labeled char[] grow.  

- Ali Fracyon


Screenshot 2024-07-10 at 11.53.04 AM.png

Mobile Ads SDK Forum Advisor

unread,
Jul 10, 2024, 6:02:11 PMJul 10
to mdfs...@gmail.com, google-adm...@googlegroups.com
Hi,

Thank you for providing detail info. I've raised this concern to the team. I will update here if any resolution will come, meanwhile your patience is important.
Thanks

Mobile Ads SDK Forum Advisor

unread,
Jul 10, 2024, 6:37:37 PMJul 10
to mdfs...@gmail.com, google-adm...@googlegroups.com
Hi,

This could be an artifact of WebView, could be something that gets garbage collected later. 
There is no issue from SDK side.

Luis Gualandi

unread,
Sep 13, 2024, 1:57:42 PMSep 13
to Google Mobile Ads SDK Developers
I'm seeing a very similar behavior when testing an iOS app in Xcode. A steady increase in memory use (~200k- 500k  ) every time a banner refreshes, in a classic memory leak pattern.
Profiling in the leaks instrument no leaks are detected, though.
I've done some pretty long tests and the garbage collector never comes, it seems to just keeps growing forever. When is the GC supposed to act, then?
I'm using Admob directly on Unity, tested on Google mobile ads 10.14 and 11.7.0.
On Android I can say that crashes and anrs are pressing significantly and much higher when filtered to low memory devices. Also my ad free version has almost 0 crashes/anrs. This all indicates there's some bad memory management on Admobs side.

Mobile Ads SDK Forum Advisor

unread,
Sep 16, 2024, 2:03:35 AMSep 16
to luis_muss...@hotmail.com, google-adm...@googlegroups.com

Hi,

I'm afraid that we'll need detailed debug information from a device where it's observed in order to actually make any progress in diagnosing this. The only way for us to investigate further is by creating a project where the issue is reproducible.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002tJlLlQAK&entry.80707362=00245510

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Luis Gualandi

unread,
Sep 17, 2024, 6:30:52 PMSep 17
to Google Mobile Ads SDK Developers

Hi,

I'll try to prepare something. I'm struggling a bit to get detailed data from Xcode because for some reason when Admob is initialized the allocations instrument keeps throwing an exception

Luis Gualandi

unread,
Sep 20, 2024, 4:38:12 PMSep 20
to Google Mobile Ads SDK Developers
Hi,

I sent the files in the link. It contains the Unity iOS project which is basically a project that displays a banner with copy pasted code from the documentation (replace your ad units, app id etc). I'm testing on test mode, Unity version 2021.3.34f1 and Xcode 15.4.
It also contains the trace file from the Xcode allocations tool.
By profiling in the allocations tool I noticed a steady increase in the VM:IOSurface and VM:Foundation persistent items. The VM:Foundation will increase by exactly 1 every banner refresh, while VM:IOSurface is more unstable but will average 1 extra item per banner refresh. VM:IOSurface leaking items, which manages pixel buffers, seem to be hidden and not shown when expanded, the items shown are being reutilized and probably not contributing to the bloat.

xcode_allocations.png
xcode_allocations_vm_foundation.png
xcode_allocations_vm_iosurface.png

The stack trace from the VM:Foundation items points to webview and javascript stuff:  
mach_vm_allocate
vm_allocate
NSAllocateMemoryPages
-[_NSPlaceholderData initWithBytes:length:copy:deallocator:]
0x105874080
0x105862478
0x1058b10ec
0x1058b0bc8
0x1058b1118
WTF::Detail::CallableWrapper<WTF::CompletionHandler<void (IPC::Decoder*)> IPC::Connection::makeAsyncReplyCompletionHandler<Messages::WebPage::RunJavaScriptInFrameInScriptWorld, WebKit::WebPageProxy::runJavaScriptInFrameInScriptWorld(WebCore::RunJavaScriptParameters&&, std::__1::optional<WebCore::ProcessQualified<WTF::ObjectIdentifierGeneric<WebCore::FrameIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits<unsigned long long>, unsigned long long>>>, API::ContentWorld&, WTF::CompletionHandler<void (std::experimental::fundamentals_v3::expected<WTF::RefPtr<API::SerializedScriptValue, WTF::RawPtrTraits<API::SerializedScriptValue>, WTF::DefaultRefDerefTraits<API::SerializedScriptValue>>, WebCore::ExceptionDetails>&&)>&&)::$_0>(WebKit::WebPageProxy::runJavaScriptInFrameInScriptWorld(WebCore::RunJavaScriptParameters&&, std::__1::optional<WebCore::ProcessQualified<WTF::ObjectIdentifierGeneric<WebCore::FrameIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits<unsigned long long>, unsigned long long>>>, API::ContentWorld&, WTF::CompletionHandler<void (std::experimental::fundamentals_v3::expected<WTF::RefPtr<API::SerializedScriptValue, WTF::RawPtrTraits<API::SerializedScriptValue>, WTF::DefaultRefDerefTraits<API::SerializedScriptValue>>, WebCore::ExceptionDetails>&&)>&&)::$_0&&, WTF::ThreadLikeAssertion)::'lambda'(IPC::Decoder*), void, IPC::Decoder*>::call(IPC::Decoder*)
WTF::Detail::CallableWrapper<WebKit::AuxiliaryProcessProxy::sendMessage(WTF::UniqueRef<IPC::Encoder>&&, WTF::OptionSet<IPC::SendOption>, std::__1::optional<IPC::ConnectionAsyncReplyHandler>, WebKit::AuxiliaryProcessProxy::ShouldStartProcessThrottlerActivity)::$_1, void, IPC::Decoder*>::call(IPC::Decoder*)
IPC::Connection::dispatchMessage(WTF::UniqueRef<IPC::Decoder>)
IPC::Connection::dispatchIncomingMessages()
WTF::RunLoop::performWork()
WTF::RunLoop::performWork(void*)
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
__CFRunLoopDoSource0
__CFRunLoopDoSources0
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
-[UnityFramework runUIApplicationMainWithArgc:argv:]
main
start

Additionally, the following are errors in Xcode log that appear in between banners, it seems to be trying to terminate a proccess but failing:
nw_connection_add_timestamp_locked_on_nw_queue [C7] Hit maximum timestamp count, will start dropping events
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
0x1190243c0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=1492, error: (null)
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
0x1190252c0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=1492, error: (null)
Failed to terminate process: Error Domain=com.apple.extensionKit.errorDomain Code=18 "(null)" UserInfo={NSUnderlyingError=0x303af9aa0 {Error Domain=RBSRequestErrorDomain Code=3 "No such process found" UserInfo={NSLocalizedFailureReason=No such process found}}}
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))" UserInfo={NSLocalizedFailureReason=((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))}>

Mobile Ads SDK Forum Advisor

unread,
Sep 23, 2024, 2:57:53 AMSep 23
to luis_muss...@hotmail.com, google-adm...@googlegroups.com
Hi,

Thank you for providing requested details. I've raised this concern to the team. I will update here if any resolution will come, meanwhile your patience is important.

احمد الشنباري

unread,
Sep 23, 2024, 5:27:58 AMSep 23
to Luis Gualandi, Google Mobile Ads SDK Developers
.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/23a4d4e0-fe6e-4f97-a1ee-4dabd86850ffn%40googlegroups.com.

دون乡الہٰموتہٰ乡

unread,
Sep 23, 2024, 6:38:49 AMSep 23
to احمد الشنباري, Luis Gualandi, Google Mobile Ads SDK Developers

Mobile Ads SDK Forum Advisor

unread,
Sep 24, 2024, 2:58:01 AMSep 24
to a7m...@gmail.com, ahmdals...@gmail.com, luis_muss...@hotmail.com, google-adm...@googlegroups.com
Hi,

This issue could be an artifact of WebView, could be something that gets garbage collected later. It's not controlled by Mobile Ads SDK.

Sunil

unread,
Sep 24, 2024, 1:48:58 PMSep 24
to Google Mobile Ads SDK Developers
Reply all
Reply to author
Forward
0 new messages
Search
Clear search
Close search
Google apps
Main menu