Is this a Swift 4.2 regression, object not deallocating?

This simple code works in Xcode 9.x but does not behave the same in Xcode 10 GM. deinit is simply never called.

class Ref {
  weak var obj: Obj?
}

class Obj {
  deinit {
    print("deinit")
  }
}

var obj: Obj? = Obj()
let ref = Ref()
ref.obj = obj
obj = nil

It gets even worth. because if you add ref.obj = nil at the end the object still does not deallocate.

I tested it only in playground. I'll create a small project and test it there. Works in a small command line app.

Why does can this happen in playground though?

Playgrounds take extra references to things sometimes in order to display them in the sidebar, but it's considered a bug when that happens. Please file!

1 Like