CameraView icon indicating copy to clipboard operation
CameraView copied to clipboard

[BUG] Memory leak and solution

Open samchen7910 opened this issue 10 months ago • 6 comments

Issue: The memory has not been released after the view is dismissed.

Image Image

Reason: Retain cycle

Solution: Add weak to all parent variables

Image

samchen7910 avatar Mar 13 '25 13:03 samchen7910

I’m experiencing the same issue. Although I set the weak, it didn’t resolve the problem. Have you discovered any other potential solutions on this matter?

4pplipsedev avatar Mar 31 '25 16:03 4pplipsedev

After changing all parent references to weak, the memory leak was resolved.

I also tested memory usage upon view dismissed and added deinit to all related classes for debugging:

CameraManagerPhotoOutput CameraManagerVideoOutput CameraMetalView CameraGridView CameraManagerMotionManager CameraManagerNotificationCenter

samchen7910 avatar Apr 01 '25 13:04 samchen7910

@samchen7910 why not push up a PR?

pauluhn avatar Apr 05 '25 02:04 pauluhn

Thanks for PR, @pauluhn. I've been swamped settling stuff into my new home.

samchen7910 avatar Apr 07 '25 12:04 samchen7910

There is still an error. When I use the camera in fullScreenCover, it crashes when I dismiss it because the parent=nil.

daiyangyang945 avatar Apr 26 '25 16:04 daiyangyang945

Stumbled upon this issue (without noticing the memory leak myself). I've opened #104 with a fix. Not sure when this will be approved, but in meantime you can point SPM to commit 857a08ee75060193e82c1fc9822a3b9f1688ff42 and get the fix in!

Cc: @pauluhn / @samchen7910

@daiyangyang945 I tested the PR with fullScreenCover and it was working as expected.

samdogg7 avatar May 22 '25 12:05 samdogg7