0

Why do I get the following behaviour in playground?

class A {
}

class B {
    weak var theA: A?
}

let a = A()
_getRetainCount(a) // output is 2 . OK.
var b = B()
b.theA = a
_getRetainCount(a) // output is 3 . WHY?.

As you can see the reference in class B is weak to the A object but playground somehow increases this count.

This doesn't happen in a normal project.

Durdu
  • 3,627
  • 1
  • 20
  • 38
  • https://stackoverflow.com/questions/24600008/non-strong-references-not-working-in-playground, https://stackoverflow.com/questions/24082011/weak-references-in-swift-playground-dont-work-as-expected. – Martin R Nov 02 '18 at 14:36
  • And of course: https://stackoverflow.com/questions/4636146/when-to-use-retaincount – Martin R Nov 02 '18 at 14:36
  • @MartinR You are all present in the iOS related questions (at least) :)) . Thanks for your answer! I was googling and found these answers as well and ofc playground is not reliable but I was curios if there was any setting or some piece of documentation I missed. – Durdu Nov 02 '18 at 14:40

0 Answers0