Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComposeUIViewController not released at all #3201

Closed
Alex009 opened this issue May 23, 2023 · 7 comments · Fixed by JetBrains/compose-multiplatform-core#728
Closed

ComposeUIViewController not released at all #3201

Alex009 opened this issue May 23, 2023 · 7 comments · Fixed by JetBrains/compose-multiplatform-core#728
Assignees
Labels
bug Something isn't working ios reproduced

Comments

@Alex009
Copy link
Collaborator

Alex009 commented May 23, 2023

Describe the bug
I embed ComposeUIViewController to native iOS navigation. When i navigate back current ComposeUIViewController should release memory, but it's not.

Affected platforms

  • iOS

Versions

  • Kotlin version*: 1.8.10 , 1.8.20
  • Compose Multiplatform version*: 1.4.0
  • OS version(s)* (required for Desktop and iOS issues): iOS 16.4 (simulator)
  • OS architecture (x86 or arm64): tested on arm64

To Reproduce

  1. clone https://github.com/Alex009/compose-ui-vc-leak
  2. run app
  3. navigate back to root (press back at top left corner)
  4. check memory - it's not released
  5. run Simulate memory warning on simulator - you see in logs that many ComposeUIViewController got this warning

Expected behavior
ComposeUIViewController should release memory when it's not used by app.

Screenshots
image

Additional context
Add any other context about the problem here.

@Alex009 Alex009 added bug Something isn't working submitted labels May 23, 2023
@Alex009
Copy link
Collaborator Author

Alex009 commented May 23, 2023

i think problem is reference cycle with keyboard observer

https://github.com/JetBrains/compose-multiplatform-core/blob/cf7d6a444f4a5dc6379d49de4c8a0867e738a588/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeWindow.uikit.kt#L119

as i know for K/N difficult to understand cycles between Kotlin & ObjC boundaries

@alexzhirkevich
Copy link
Contributor

Had the same problem. I thought that was my fault of leaked reference somewhere :)

@warnyul
Copy link

warnyul commented May 29, 2023

I have a workaround for this. I just set the ComposeUIViewController.view to an empty UIView.

@warnyul
Copy link

warnyul commented May 29, 2023

But it not solved my original memory leaks. Somewhy lot of IOSurface is stuck in the memory:

Screenshot 2023-05-29 at 23 45 35

Do you experience the same?

@elijah-semyonov
Copy link
Contributor

The problem is pinned down and is related to GC. In this particular case it's resolved via using new Kotlin language feature to manually release native API reference counted objects when their lifetime is critical for correct usage of API (CAMetalDrawable is living for too long and holds IOSurface memory). The latest possible moment the fix arrives is release associated with Kotlin 1.9.0.

@elijah-semyonov
Copy link
Contributor

I found more sources of this leak caused by interaction of GC and ARC-managed memory, to be resolved later

@elijah-semyonov
Copy link
Contributor

The leak of ComposeWindow itself (but not all associated resources) is fixed in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ios reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants