I have a pretty simple class:
class TestClass {}
then I created an instance of this class:
let instance = TestClass()
After that I started my project (debug build) and ran command in Xcode console:
language swift refcount instance
and what I got was:
refcount data: (strong = 3, unowned = 1, weak = 1)
I wonder why my instance has 3 strong references, 1 unowned and 1 weak, if in fact there is only 1 strong reference.
The reason
language swift refcount instanceis showing 3 strong references is probably because of retaining your instance inside of debug code. Moreover, if you will repeat the command, you will get incrementing results:I think this is kind of Xcode/runtime bug.
Also, you can use
CFGetRetainCountto check reference count on an instance:The reason you get "2" is
instanceis retained bylet instancestatic variable, as well as it is retained inside theCFGetRetainCountfunction. You can proof this by calling