compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

`BasicAlertDialog` Crash iOS with OOM (Memory Leak)

Open chrisjenx opened this issue 1 year ago • 8 comments

Describe the bug Since 1.6.10x, m3 BasicAlertDialogs with lots of content will recompose and leak memory causing out of memory crashes on iOS.

iOS will throw didReceiveMemoryWarning then crash:

Screenshot 2024-05-22 at 5 38 33 PM

More diagnostics to follow once got a sample project for you.

Affected platforms

  • iOS

Versions

  • Libraries:
    • Compose Multiplatform version: 1.6.10 (or RC's)
    • Decompose: 3.0
  • Kotlin version: 1.9.23
  • Device (model or simulator for iOS issues): Physical iPhone (Simulators do no crash) iOS 17.4

To Reproduce

More to follow, but full screen dialogs will recompose unconditionally and crash (will try and create a reproduction project for you)

Steps to reproduce the behavior:

  1. Open Dialog with scrollable content
  2. Scroll Content very slowly, app will crash after it runs out of memory drawing

Expected behavior Don't OOM and crash on iOS

Screenshots Screenshot 2024-05-22 at 5 38 33 PM

Additional context I thought it was related to Kotlin 2.x but downgraded and still an issue, downgraded CMP to 1.6.1 and now not crashing.

Link to trace from Profling iOS App, looks like a Skia Canvas draw leak in 1.6.10. If you stop moving it will dealloc the objects, but scrolling slowly will not release quick enough.

https://drive.google.com/drive/folders/1UUPOyAWaeg7uTKaXc5EMCp-03jSy4hrk?usp=sharing

chrisjenx avatar May 22 '24 23:05 chrisjenx

Hello! I'll notify the team about that, however, a small reproducible example would really help. Could you please attach it once you've made it to your first message?

mazunin-v-jb avatar May 23 '24 00:05 mazunin-v-jb

Yeah we're working on deploying a hot fix to users once that's done I'll create a sample for y'all

chrisjenx avatar May 23 '24 01:05 chrisjenx

Added Trace, easy to reproduce, any dialog with scrollable content, scroll SLOWLY and you'll eventually run out of memory

chrisjenx avatar May 23 '24 03:05 chrisjenx

Unfortunately, I wasn't able to successfully reproduce this crash. Memory usage on a small project from template was about 70 mb and didn't increase no matter how I scrolled. Could you please make a reproducible example?

mazunin-v-jb avatar May 23 '24 18:05 mazunin-v-jb

Unfortunately, I wasn't able to successfully reproduce this crash. Memory usage on a small project from template was about 70 mb and didn't increase no matter how I scrolled. Could you please make a reproducible example?

Dang, OK, will try and create a sample project. Sorry about that

chrisjenx avatar May 23 '24 18:05 chrisjenx

Unfortunately, I wasn't able to successfully reproduce this crash. Memory usage on a small project from template was about 70 mb and didn't increase no matter how I scrolled. Could you please make a reproducible example?

Oh just checking this ONLY happens on a physical device, simulators are fine (faster/more ram from host machine)

chrisjenx avatar May 23 '24 18:05 chrisjenx

@mazunin-v-jb As requested: DialogCrash.zip

Launch app on physical iPhone, open dialog, scroll slowly (will be jerky vs previous versions) and then will suddenly crash.

I should have noted it was the BasicAlertDialogs from the m3 lib

chrisjenx avatar May 25 '24 16:05 chrisjenx

Nvm mind, I tested on the foundation Dialog and the same thing, guessing it's an underlying skia issue from what I can tell.

chrisjenx avatar May 25 '24 16:05 chrisjenx

@chrisjenx many thanks! I haven't reproduced the crash, but the memory warning was received many times, and memory consumption is very weird. We'll look at it

mazunin-v-jb avatar May 27 '24 13:05 mazunin-v-jb

Oh good, maybe a placebo, but 1.6.10 doesn't feel as smooth as 1.6.0 potentially related if it's over drawing, leaking, etc

chrisjenx avatar May 27 '24 15:05 chrisjenx

@mazunin-v-jb I will give 1.6.11 ago, I'm wondering if this was the cause of the OOM https://github.com/JetBrains/compose-multiplatform-core/pull/1355

chrisjenx avatar Jun 03 '24 20:06 chrisjenx

Tested 1.6.11, still crashing for me. Looks like it's something else :(

(It's actually worse after some more testing)

chrisjenx avatar Jun 05 '24 02:06 chrisjenx

Initial testing, looks like https://github.com/JetBrains/compose-multiplatform-core/pull/1390 fixed it, just running profiling now.

chrisjenx avatar Jul 06 '24 15:07 chrisjenx

So far looks like peak memory usage is 90mb on the demo project, no more OOM crashes, still churning memory but at least not exploding. Will test on my main project then close if doesn't crash there.

chrisjenx avatar Jul 06 '24 15:07 chrisjenx

Looks like this is resolved

chrisjenx avatar Jul 06 '24 18:07 chrisjenx

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 13:08 okushnikov