Swift uses Automatic Link Counting to free objects that are no longer referenced and therefore no longer needed. The Swift Reference Guide [1] states the following:
Each time you create a new instance of a class, ARC allocates a piece of memory to store information about this instance. This memory stores information [...] on the values โโof any stored properties associated with this instance.
I assume the reference count will be stored as an integer. Can the counter be affected by overflow? If so, then what consequences will this have for my program, will the objects still received by the links from others simply be freed?
As an example: if the counter was, say, an unsigned integer of 2 bytes, this would set the upper limit of the object references (with reference counting still correct) to about 130 thousand. As soon as this upper limit is reached, and the object receives the link once again, this will increment the counter by one, again setting it to 0.
[1] https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html
source share