79 days ago · Tech · hide · Fediverse post

New in Swift 6.4 (which at the time of writing is in beta as part of Xcode 27) is a warning which is emitted when a nested closure performs a weak capture while the parent closure implicitly captures that object as a strong reference.At first glance, that new diagnostic could be a bit puzzling, since it might seem unnecessary to have to specify such a weak capture twice (or, alternatively, move it to the parent closure’s capture list), but it turns out that it’s an incredibly useful new warning that can help us avoid a quite common kind of memory management bug.Take the following code as an example. It performs a nested weak self capture within the closure passed to the call to loadNearbyFriends, while not (explicitly) capturing self at all within the parent closure:@MainActor final class NearbyFriendsViewModel { private(set) var friends = [Friend]() private var timer: Timer? private let service: FriendsService ... @MainActor deinit { timer?.invalidate() } func startScanning() { timer…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town