AppLovin / AppLovin-MAX-SDK-iOS

Other
88 stars 71 forks source link

【Crash】Excessive Ad-Related Processes Leading to Performance Degradation and Crashes #378

Open FoneG opened 2 days ago

FoneG commented 2 days ago

MAX SDK Version

AppLovinSDK, 12.4.1

Device/Platform Info iPhone12,3 iOS 17.6.1

Current Behavior

While reviewing the Firebase crash logs, we observed that a large number of ad-related processes and threads are being generated, with over 20 instances of redundant or duplicate tasks linked to ad loading and caching. These tasks, such as ALAsyncTaskCacheHTMLResources, are being repeatedly executed, significantly adding to system overhead and causing performance degradation. These multiple threads, many of which appear to be unnecessary, are running concurrently, putting strain on both the main queue and background threads, and potentially leading to crashes.

Thread 50 name:   Dispatch queue: com.applovin.sdk.caching.html.47b33cda2224601004c2632a2f67e476fb13066f (QOS: UNSPECIFIED)
Thread 50:
0   libsystem_kernel.dylib                 0x1cb9bd5e0 __ulock_wait + 8
1   libsystem_platform.dylib               0x1dc04382c _os_unfair_lock_lock_slow + 172
2   libobjc.A.dylib                        0x187316dbc objc_sync_enter + 36
3   AppLovinSDK                            0x1046e9f28 -[ALAsyncTaskCacheResource main] + 192
4   Foundation                             0x18840d2ac __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 16
5   Foundation                             0x1884129c0 __NSOQSchedule_f + 172
6   libdispatch.dylib                      0x195674114 _dispatch_block_async_invoke2 + 148
7   libdispatch.dylib                      0x195664fdc _dispatch_client_callout + 20
8   libdispatch.dylib                      0x19566846c _dispatch_continuation_pop + 504
9   libdispatch.dylib                      0x195667ad4 _dispatch_async_redirect_invoke + 584
10  libdispatch.dylib                      0x195676a6c _dispatch_root_queue_drain + 396
11  libdispatch.dylib                      0x195677284 _dispatch_worker_thread2 + 164
12  libsystem_pthread.dylib                0x1dc0d9dbc _pthread_wqthread + 228
13  libsystem_pthread.dylib                0x1dc0d9b98 start_wqthread + 8

Expected Behavior

The ad-related processes should be optimized to avoid creating too many concurrent threads, especially in scenarios where they do not contribute to user experience or app functionality. The SDK should reduce redundant task creation and better manage process lifecycles to avoid overwhelming the system.

How to Reproduce

While this issue is not consistently reproducible, it often occurs during extended usage after ads are repeatedly loaded and cached.

Additional Info

This is the code

- (void)loadMaxAd:(NSString *)placementID {
    MAAdView *adView = [[MAAdView alloc] initWithAdUnitIdentifier:placementID adFormat:MAAdFormat.banner];
    adView.delegate = self;
    adView.frame = CGRectMake(0, 0, 320, 50);
    [adView loadAd];
    self.adView = adView;
}

- (void)loadAdmobAd:(NSString *)placementID {
    GADBannerView *adView = [[GADBannerView alloc] initWithAdSize:GADAdSizeBanner];
    adView.adUnitID = placementID;
    adView.delegate = self;
    adView.rootViewController = self.viewController;
    [adView loadRequest:[GADRequest request]];
    self.adView = adView;
}

- (void)startAutoRefresh{
    if ([self.adView isKindOfClass:[MAAdView class]]) {
        [(MAAdView *)self.adView startAutoRefresh];
    }else if ([self.adView isKindOfClass:[GADBannerView class]]){
        [(GADBannerView *)self.adView setAutoloadEnabled:YES];
    }
}

- (void)stopAutoRefresh{
    if ([self.adView isKindOfClass:[MAAdView class]]) {
        [(MAAdView *)self.adView setExtraParameterForKey: @"allow_pause_auto_refresh_immediately" value: @"true"];
        [(MAAdView *)self.adView stopAutoRefresh];
    }else if ([self.adView isKindOfClass:[GADBannerView class]]){
        [(GADBannerView *)self.adView setAutoloadEnabled:NO];
    }
}
FoneG commented 1 day ago

crash1.txt

applovinAsh commented 1 hour ago

Thank you for reporting the issue. We are investigating it. We will update the thread when we have more information.

Can you provide the percentage of users that are experiencing this issue?

alexchernokun commented 47 minutes ago

Hi team,

We’ve also experienced similar memory leaks that resulted in crashes. We observed a significant number of memory leaks related to ALAsyncTaskCacheResource. Additionally, ALAtomicBoolean is responsible for numerous leaked allocations.

We were able to reproduce the issue using AppLovin Demo app

AppLovinDemoLeaks