Will referencing an array of instances of a class in a class create a strong reference cycle?

45 Views Asked by At

I have the following class:

class Circle: CustomStringConvertible, Hashable, Equatable
{
    ...
    var bonus5Circles = [Circle]()
    ...
}

Now, in most cases the bonus5Circles array will be empty, but in some cases it will contain some subset of Circles. This seems to function properly in code, but my question is whether this is creating a strong reference cycle. I have noticed leaks that I cannot track down in functions when a bonus is created, and was wondering if it could be tracked to this property.

1

There are 1 best solutions below

0
On

After asking this question I wrote a playground with analogous code. I found that there is no issue deinitializing instances of the class UNLESS the class instance with the non-empty array contains itself, in which case you do have a strong reference cycle.