News for hackers. Stuff that matters.
Re:Apple’s use of Swift in iOS 12 by dvlsg on Friday September 28, 2018 @12:43PM (#18094780)
Isn't reference counting just a different style of garbage collection? I see lots of articles saying that swift both is and isn't garbage collected, and I'm curious what the proper answer is here.
Re:Apple’s use of Swift in iOS 12 by ppeetteerr on Friday September 28, 2018 @02:47PM (#18095942)
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.

Re:Apple’s use of Swift in iOS 12 by madmax96 on Friday September 28, 2018 @01:28PM (#18095175)
Yes, but the overhead is much smaller compared to other techniques, and it's simpler to predict runtime behavior because there is no nondeterminism when ignoring the runtime which would otherwise be introduced by collector behavior.
Re:Apple’s use of Swift in iOS 12 by khkjb80 on Friday September 28, 2018 @01:40PM (#18095303)
with all those differences, reference counting is not garbage collecting, it's like calling free in c garbage collecting, which is incorrect.
Re:Apple’s use of Swift in iOS 12 by madmax96 on Friday September 28, 2018 @08:10PM (#18097968)
https://en.m.wikipedia.org/wiki/Garbage_collection_(computer...

Reference counting is listed as a strategy to achieve garbage collection. Broadly speaking, garbage collection is the process of automatically managing the lifecycles of objects in memory, which reference counting certainly achieves.