Closed nighthawk closed 2 months ago
The retain cycle is triggered by LiveSessionCoordinator
's init
method which has this line:
self.navigationPath = [.init(url: url, coordinator: .init(session: self, url: self.url))]
Note how self
is passed there, which causes the retain cycle.
I noticed this when I didn't have my local server running and the LiveView in the app couldn't connect, and when I navigated away from the LiveView in my app and it was no longer in the view hierarchy, the live view session kept trying to reconnect.
Seems like that retain cycle hid two other issues here. Since LiveSessionCoordinator
will now get deallocated properly, the two unused self
usages need to be removed as they can fire in rare cases after it got deallocated, which then crashes.
This should go under Fixed
in the CHANGELOG.md
Sure thing. Change log updated.
@nighthawk thank you!
LiveViewCoordinator
is initialised fromLiveSessionCoordinator
, which gets passed in as a parameter toinit
and then retained by the view coordinator. This causes a retain cycle.Additionally, this is also retained by the
handleEvent
assession
was used directly in the closure, which then retained it.This commit fixes both by using a weak reference from the view coordinator to the session coordinator, and accessing the session via the weak
self
reference.