Memory graph looped arrow meaning

I've gone over the memory graph debugger documentation and WWDC videos.

The available documentation is sparse and does not go into any detail of what things mean.

Through usage I have a fair understanding of what most symbols and reference lines mean except for the line from an object that loops back on itself in the top right corner of an object symbol. I have noticed it always appears on dictionaries, I have this on one of my own classes and want to know what it means?

Answered by DTS Engineer in 823889022

It looks like your class has a pointer to itself. Consider this program:

class MyClass {
    var other1: MyClass?
    var other2: MyClass?
    var other3: MyClass?
}

func main() {
    let m = MyClass()
    m.other1 = m
    m.other2 = m
    m.other3 = m
    print()
}

main()

If you set a breakpoint on the print(…) statement and look at the memory graph there, you’ll see similar output.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It looks like your class has a pointer to itself. Consider this program:

class MyClass {
    var other1: MyClass?
    var other2: MyClass?
    var other3: MyClass?
}

func main() {
    let m = MyClass()
    m.other1 = m
    m.other2 = m
    m.other3 = m
    print()
}

main()

If you set a breakpoint on the print(…) statement and look at the memory graph there, you’ll see similar output.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

Is that the only case that loop arrow is used?

I don’t know for sure.

We have one on class A and the pointer name on the loop is for a completely different class B.

It’s possible to imagine how that might happen. One obvious mechanism is subclassing (if A is as subclass of B), but you can also imagine it happening in ‘broken’ cases as well.

I recommend that you explore this specific case in the debugger, that is, get the address of A, the value of the pointer to B, and see if they match.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for all the help, I still haven't gotten to the bottom of the issue.

It’s possible to imagine how that might happen. One obvious mechanism is subclassing (if A is as subclass of B), but you can also imagine it happening in ‘broken’ cases as well.

The referenced class is not a subclass of the owning class and they not share anything in common at all code wise. I'm not following what would an example of a ‘broken’ case be?

I recommend that you explore this specific case in the debugger, that is, get the address of A, the value of the pointer to B, and see if they match.

The memory addresses of the two are unique, I do see the pointer has a "+16" after it's name, presumably a byte offset. Can this be useful at all in determining what is happening here?

Memory graph looped arrow meaning
 
 
Q