Post

Replies

Boosts

Views

Activity

Reply to Memory leaks caused by closures
I think this is best illustrated with a capture list. You can capture the object, but it's not the default behavior. final class Object { var closure: () -> Object? = { nil } } @Test func test() { do { var object: Optional = Object() object!.closure = { object } weak var weakObject = object object = nil #expect(weakObject == nil) } do { var object: Optional = Object() object!.closure = { [object] in object } weak var weakObject = object object = nil #expect(weakObject != nil) } }
Oct ’24
Reply to Memory leaks caused by closures
I think this is best illustrated with a capture list. You can capture the object, but it's not the default behavior. final class Object { var closure: () -> Object? = { nil } } @Test func test() { do { var object: Optional = Object() object!.closure = { object } weak var weakObject = object object = nil #expect(weakObject == nil) } do { var object: Optional = Object() object!.closure = { [object] in object } weak var weakObject = object object = nil #expect(weakObject != nil) } }
Replies
Boosts
Views
Activity
Oct ’24
Reply to How to pass Child Class reference as Parent Class
You are conflating the ideas of instances and metatypes. Is that sentence enough for you to solve the problem or do you need to know where to find links with relevant information?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’24
Reply to CKQueryOperation in private database produces 500 errors from server and in CloudKit Console
I've seen this several times in the past year, including the past three days. Please stop doing this!
Replies
Boosts
Views
Activity
Apr ’24