|
As per the title. I reported a bug to Apple and mentioned it on the Apple forums some months ago here: https://developer.apple.com/forums/thread/729197 Essentially, using the sample code below, if you observe the printouts, the class is not deallocated if multiple presentationDetents are present.
In an actual use case, imagine the deinit printer is a ViewModel that would now not be deinitalised correctly. I've raised this with Apple, FB12213332 but have since heard nothing back, I was wondering surely... I can't be the only one that's noticed this. Wondering if I'm having a brainfart and I'm actually missing something here... Any help or suggestions would be appreciated! |
|
|
|
Try to put object in .task modifier like so
|
|
In my case I init environment object for |
|
Then i have a question, why do you need to deinit it? You create some object upper in hierarchy or in environment then reference to this object in subview or detail view, do something with it, then close detail view and you want that object to deinit???? Then you lose any reference to that object at all. In any case as soon there will be no reference to that object anywhere in the app, ARC will count as zero reference and will destroy that object... As far as I understand that all... |
|
This is the point! |
|
I just reproduced this bug in the test project. https://github.com/schornon/PresentationDetentsLeak |
|
I think in this case you need to pass vm object to enironment like so:
|
|
Well, then ContentViewModel will be available in DetailsView and that is a little strange because DetailsView has the own VM. |
|
If you find any other solution, post for others as well. Seems like a bug in SwiftUI, but I couldn't come up with another solution for this matter... |
|
Hey @Kaiman, I've run into this issue before, and it can indeed be frustrating. It's great that you've reported it to Apple. One workaround I've found is to use a custom presentation transition instead of relying on the built-in presentationDetents. It's a bit more work, but it can help with memory management. Hope this helps! Best regards, |
|
Hi all, thanks for the suggestions and help. Happy to report that Apple got back to me on the bug report and this is no longer an issue in iOS 17.4.1! - 🎊 It could have been fixed before in a previous version of iOS 17.x - but I haven't had a chance to check those. |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.