3 ms·
Not quite the same as garbage collection. When an object has a pointer null'ed, that object's reference count is reduced by 1. When the reference count reaches
by ppeetteerr 8y ago
Not quite the same as garbage collection. When an object has a pointer null'ed, that object's reference count is reduced by 1. When the reference count reaches 0, that object is remove from memory. You could still cause memory leaks like so:
```
struct Node {
var next: Node?
var prev: Node?
}
var a = Node(next: nil, prev: nil)
let b = Node(next: nil, prev: a)
a.next = b
```
These two objects will persist in memory for the entire life of the app even when all reference to a and b are gone, except for their references to one another.