class Node {
var successors: Array<Node>
init(_ successors: Array<Node>) {
self.successors = successors
}
}
let a = Node([b])
let b = Node([a])
This innocent piece of code gives an error; error: circular reference it says. The weird thing is that it was repeated 5 times.
.
An attempt to put there weak/unowned didn't do anything. How to get rid of this error?
cukr
2
var a = Node([])
let b = Node([a])
a.successors = [b]
I'm assuming that this is in the context of main.swift or a playground
2 Likes
cukr
4
I forgot to mention - I got rid of circular references between lines of code, but there is still a circular reference between objects in memory. It would easily lead to a memory leak.
1 Like