Is this a Swift 4.2 regression, object not deallocating?

(Adrian Zubarev) #1

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 {

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?

Is there a reason why `didSet` not being called on a weak property that becomes nil?
(Jordan Rose) #2

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!