microsoft / appcenter-sdk-android

Development repository for the App Center SDK for Android
Other
277 stars 134 forks source link

Memory leak due to didn't unregister broadcastReceiver on Distribute. #1603

Closed gediseer closed 2 years ago

gediseer commented 2 years ago

Description

Memroy leak has been found on All Activity, heap dump is below: image Looks lile it's caused by not unregistering the broadcast receiver after it's been registered on every "onResume" of each activity. suggested fixed is unregister broadcast receiver on "onPause" image

Please describe the issue you are facing using the SDK. The memory usage keep increasing while the "onResume" callback of each Activity being call many times, and it's won't decrease until OOM.

Repro Steps

Please list the steps used to reproduce your issue.

  1. start an Activity whose "onResume" callback will be observed by Appcenter.
  2. click back button on navigation bar, and then go back to the previous activity, to make sure it's "onResume" callback being invoded again.
  3. check the memory usage on Android Studio Profiler.

Details

  1. Which SDK version are you using?
    • 4.4.2
  2. Which OS version did you experience the issue on?
    • Android 12
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    • Google Pixel 4xl physical device
  4. What third party libraries are you using?
    • com.microsoft.appcenter:appcenter-distribute:4.4.2
  5. Please enable verbose logging for your app using AppCenter.setLogLevel(Log.VERBOSE) before your call to AppCenter.start(...) and include the logs here:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2022-03-01 15:07:16.316 21265-21265/com.microsoft.example I/AppCenter: App Center SDK configured successfully. 2022-03-01 15:07:16.316 21265-21265/com.microsoft.example D/AppCenter: Cannot read instrumentation variables in a non-test environment. 2022-03-01 15:07:16.316 21265-21265/com.microsoft.example D/AppCenter: Cannot read instrumentation variables in a non-test environment. 2022-03-01 15:07:16.327 21265-21318/com.microsoft.example D/AppCenter: Loaded stored sessions: {} 2022-03-01 15:07:16.331 21265-21318/com.microsoft.example W/AppCenter: Unable to get installID from Shared Preferences 2022-03-01 15:07:16.331 21265-21321/com.microsoft.example D/AppCenter: Network 289 is available. 2022-03-01 15:07:16.331 21265-21321/com.microsoft.example D/AppCenter: Network has been connected. 2022-03-01 15:07:16.343 21265-21318/com.microsoft.example I/AppCenter: Changed maximum database size to 10485760 bytes. 2022-03-01 15:07:16.343 21265-21318/com.microsoft.example D/AppCenter: addGroup(group_core) 2022-03-01 15:07:16.343 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_core) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:16.344 21265-21318/com.microsoft.example D/AppCenter: App Center initialized. 2022-03-01 15:07:16.344 21265-21318/com.microsoft.example D/AppCenter: removeGroup(groupErrors) 2022-03-01 15:07:16.344 21265-21318/com.microsoft.example D/AppCenter: removeGroup(groupErrors/one) 2022-03-01 15:07:16.345 21265-21318/com.microsoft.example D/AppCenter: addGroup(groupErrors) 2022-03-01 15:07:16.346 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(groupErrors) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:16.346 21265-21318/com.microsoft.example D/AppCenter: addGroup(groupErrors/one) 2022-03-01 15:07:16.346 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(groupErrors/one) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:16.346 21265-21318/com.microsoft.example D/AppCenterCrashes: No previous minidump sub-folders. 2022-03-01 15:07:16.346 21265-21318/com.microsoft.example I/AppCenter: Crashes service started from application. 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: removeGroup(group_distribute) 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: removeGroup(group_distribute/one) 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: addGroup(group_distribute) 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_distribute) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: addGroup(group_distribute/one) 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_distribute/one) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example D/AppCenterDistribute: Distribute workflow will be resumed on activity resume event. 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example W/AppCenterDistribute: Couldn't register receiver due to activity is null. 2022-03-01 15:07:16.347 21265-21318/com.microsoft.example I/AppCenter: Distribute service started from application. 2022-03-01 15:07:16.355 21265-21318/com.microsoft.example D/AppCenter: Storing a log to the Persistence database for log type startService with flags=1 2022-03-01 15:07:16.360 21265-21318/com.microsoft.example D/AppCenter: Stored a log to the Persistence database for log type startService with databaseId=1 2022-03-01 15:07:16.360 21265-21318/com.microsoft.example D/AppCenter: enqueue(group_core) pendingLogCount=1 2022-03-01 15:07:16.360 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_core) pendingLogCount=1 batchTimeInterval=3000 2022-03-01 15:07:16.523 21265-21265/com.microsoft.example D/AppCenterDistribute: Resetting workflow on entering foreground. 2022-03-01 15:07:16.541 21265-21265/com.microsoft.example D/AppCenterDistribute: Resume distribute workflow... 2022-03-01 15:07:16.541 21265-21265/com.microsoft.example D/AppCenterDistribute: InstallerPackageName=null 2022-03-01 15:07:16.542 21265-21265/com.microsoft.example D/AppCenterDistribute: No token, need to open browser to url=https://install.appcenter.ms/apps/8889f716-03da-4355-9a7d-69f1c9aa106d/private-update-setup/?release_hash=63c791548bb8aa5ce403f283f5488e93c2322ce37c704556fd0a5b63975b3801&redirect_id=com.microsoft.example&redirect_scheme=appcenter&request_id=bdae8887-b50d-4fb0-8ed0-b71843e1b7f7&platform=Android&enable_failure_redirect=true&install_id=3b78387b-fa37-49d0-9fc7-81020ca47af4 2022-03-01 15:07:16.551 21265-21265/com.microsoft.example D/AppCenterDistribute: Default browser seems to be org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:16.551 21265-21265/com.microsoft.example D/AppCenterDistribute: And its not the picker. 2022-03-01 15:07:16.551 21265-21265/com.microsoft.example D/AppCenterDistribute: Launch browser=org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:16.564 21265-21265/com.microsoft.example D/AppCenterDistribute: The receiver for installing a new release was registered. 2022-03-01 15:07:16.806 21265-21265/com.microsoft.example D/AppCenterCrashes: The memory running level (20) was saved. 2022-03-01 15:07:17.802 21265-21327/com.microsoft.example I/WM-WorkerWrapper: Worker result SUCCESS for Work [ id=0fb3e802-1b6a-4c08-b1d5-de7d420d82ca, tags={ com.microsoft.example.distribution.AppCenterUpdateService } ] 2022-03-01 15:07:18.289 21265-21293/com.microsoft.example D/LeakCanary: Setting up flushing for Thread[AppCenter.Looper,5,main] 2022-03-01 15:07:19.386 21265-21318/com.microsoft.example D/AppCenter: triggerIngestion(group_core) pendingLogCount=1 2022-03-01 15:07:19.386 21265-21318/com.microsoft.example D/AppCenter: Trying to get 1 logs from the Persistence database for group_core 2022-03-01 15:07:19.390 21265-21318/com.microsoft.example D/AppCenter: Returning 1 log(s) with an ID, ddc04173-3dee-46cf-b589-56efed8ac58a 2022-03-01 15:07:19.390 21265-21318/com.microsoft.example D/AppCenter: The SID/ID pairs for returning log(s) is/are: 2022-03-01 15:07:19.391 21265-21318/com.microsoft.example D/AppCenter: null / 1 2022-03-01 15:07:19.391 21265-21318/com.microsoft.example D/AppCenter: ingestLogs(group_core,ddc04173-3dee-46cf-b589-56efed8ac58a) pendingLogCount=0 2022-03-01 15:07:19.394 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_core) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:19.396 21265-21357/com.microsoft.example V/AppCenter: Calling https://in.appcenter.ms/logs?api-version=1.0.0... 2022-03-01 15:07:19.396 21265-21357/com.microsoft.example V/AppCenter: Headers: {Install-ID=3b78387b-fa37-49d0-9fc7-81020ca47af4, App-Secret=****c9aa106d, Content-Type=application/json} 2022-03-01 15:07:19.397 21265-21357/com.microsoft.example V/AppCenter: { "logs": [ { "type": "startService", "timestamp": "2022-03-01T07:07:16.355Z", "device": { "sdkName": "appcenter.android", "sdkVersion": "4.4.2", "model": "AOSP on coral", "oemName": "Google", "osName": "Android", "osVersion": "12", "osBuild": "SP1A.210812.016.A1", "osApiLevel": 31, "locale": "en_US", "timeZoneOffset": 480, "screenSize": "1440x2872", "appVersion": "1.0.0.0-team", "carrierCountry": "cn", "appBuild": "2163341", "appNamespace": "com.microsoft.example" }, "services": [ "Crashes", "Distribute" ], "isOneCollectorEnabled": false } ] } 2022-03-01 15:07:21.066 21265-21357/com.microsoft.example V/AppCenter: HTTP response status=200 payload={"status":"AllLogsThrottled","validDiagnosticsIds":[],"throttledDiagnosticsIds":[],"correlationId":"ec6bcedd-5b0a-4d75-8796-a8978cbbe186"} 2022-03-01 15:07:21.068 21265-21318/com.microsoft.example D/AppCenter: Deleting logs from the Persistence database for group_core with ddc04173-3dee-46cf-b589-56efed8ac58a 2022-03-01 15:07:21.068 21265-21318/com.microsoft.example D/AppCenter: The IDs for deleting log(s) is/are: 2022-03-01 15:07:21.068 21265-21318/com.microsoft.example D/AppCenter: 1 2022-03-01 15:07:21.085 21265-21318/com.microsoft.example D/AppCenter: checkPendingLogs(group_core) pendingLogCount=0 batchTimeInterval=3000 2022-03-01 15:07:28.009 21265-21265/com.microsoft.example D/AppCenterDistribute: Resetting workflow on entering foreground. 2022-03-01 15:07:28.055 21265-21265/com.microsoft.example D/AppCenterDistribute: Resume distribute workflow... 2022-03-01 15:07:28.056 21265-21265/com.microsoft.example D/AppCenterDistribute: No token, need to open browser to url=https://install.appcenter.ms/apps/8889f716-03da-4355-9a7d-69f1c9aa106d/private-update-setup/?release_hash=63c791548bb8aa5ce403f283f5488e93c2322ce37c704556fd0a5b63975b3801&redirect_id=com.microsoft.example&redirect_scheme=appcenter&request_id=21f653bb-d3fe-4b82-a017-6e575385e73f&platform=Android&enable_failure_redirect=true&install_id=3b78387b-fa37-49d0-9fc7-81020ca47af4 2022-03-01 15:07:28.063 21265-21265/com.microsoft.example D/AppCenterDistribute: Default browser seems to be org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:28.063 21265-21265/com.microsoft.example D/AppCenterDistribute: And its not the picker. 2022-03-01 15:07:28.063 21265-21265/com.microsoft.example D/AppCenterDistribute: Launch browser=org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:28.068 21265-21265/com.microsoft.example D/AppCenterDistribute: The receiver for installing a new release was registered. 2022-03-01 15:07:28.194 21265-21265/com.microsoft.example D/AppCenterCrashes: The memory running level (20) was saved. 2022-03-01 15:07:28.892 21265-21265/com.microsoft.example D/AppCenterDistribute: Resetting workflow on entering foreground. 2022-03-01 15:07:28.893 21265-21265/com.microsoft.example D/AppCenterDistribute: Resume distribute workflow... 2022-03-01 15:07:28.893 21265-21265/com.microsoft.example D/AppCenterDistribute: No token, need to open browser to url=https://install.appcenter.ms/apps/8889f716-03da-4355-9a7d-69f1c9aa106d/private-update-setup/?release_hash=63c791548bb8aa5ce403f283f5488e93c2322ce37c704556fd0a5b63975b3801&redirect_id=com.microsoft.example&redirect_scheme=appcenter&request_id=17749a3c-9cce-4d0f-827b-ab6a4f778ce1&platform=Android&enable_failure_redirect=true&install_id=3b78387b-fa37-49d0-9fc7-81020ca47af4 2022-03-01 15:07:28.903 21265-21265/com.microsoft.example D/AppCenterDistribute: Default browser seems to be org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:28.903 21265-21265/com.microsoft.example D/AppCenterDistribute: And its not the picker. 2022-03-01 15:07:28.903 21265-21265/com.microsoft.example D/AppCenterDistribute: Launch browser=org.chromium.webview_shell/org.chromium.webview_shell.WebViewBrowserActivity 2022-03-01 15:07:28.907 21265-21265/com.microsoft.example D/AppCenterDistribute: The receiver for installing a new release was registered. 2022-03-01 15:07:29.014 21265-21265/com.microsoft.example D/AppCenterCrashes: The memory running level (20) was saved. 2022-03-01 15:07:29.517 21265-21265/com.microsoft.example D/AppCenterDistribute: Resume distribute workflow... 2022-03-01 15:07:29.517 21265-21265/com.microsoft.example D/AppCenterDistribute: The receiver for installing a new release was registered. 2022-03-01 15:08:50.972 21265-21265/com.microsoft.example D/AppCenterCrashes: The memory running level (20) was saved. 2022-03-01 15:08:51.521 21265-21265/com.microsoft.example E/ActivityThread: Activity com.microsoft.example.fre.ui.FreActivity has leaked IntentReceiver com.microsoft.appcenter.distribute.AppCenterPackageInstallerReceiver@8b495be that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity com.microsoft.example.fre.ui.FreActivity has leaked IntentReceiver com.microsoft.appcenter.distribute.AppCenterPackageInstallerReceiver@8b495be that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1717) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1494) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1757) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1723) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1711) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:724) at com.microsoft.appcenter.distribute.Distribute.registerReceiver(Distribute.java:5) at com.microsoft.appcenter.distribute.Distribute.onActivityResumed(Distribute.java:4) at android.app.Application.dispatchActivityResumed(Application.java:416) at android.app.Activity.dispatchActivityResumed(Activity.java:1397) at android.app.Activity.onResume(Activity.java:1950) at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:2) at com.microsoft.example.fre.ui.FreActivity.onResume(FreActivity.java:1) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1476) at android.app.Activity.performResume(Activity.java:8191) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4751) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4794) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:54) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2214) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

gediseer commented 2 years ago

BTW, we are moving on to finish our target android sdk 31 working now, so the appcenter:4.4.2 is essential, can you fix this ASAP to unblock our target sdk 31 work?

fabiendem commented 2 years ago

(@gediseer be aware of https://github.com/microsoft/appcenter-sdk-android/issues/1594)

gediseer commented 2 years ago

(@gediseer be aware of #1594)

thanks @fabiendem I will apply this workaround, and Do you or @AnastasiaKubova know the ETA of this leak fix? We are impacted by this bug seriously and the ETA of our target sdk 31 work is near.

AnastasiaKubova commented 2 years ago

Hi there! We don't have concrete FTE when this issue will be fixed. We will notify you when this fix will be available.

gediseer commented 2 years ago

Hi, @AnastasiaKubova, thanks for the reply, do you have any workaround to mitigate this problem? cause it blocks our release recently.

AnastasiaKubova commented 2 years ago

No, we don't have a workaround for it. We will notify you when this fix will be available.

DmitriyKirakosyan commented 2 years ago

Hi @gediseer, we just released a new version with this fix included!