This is Regarding Xcode 8 Beta 2 - I looked at the beta section but there is no category for development tools, so I'm posting this here.
I've been playing with the memory graph debugging tool in Xcode 8. I created a very contrived example to force a memory leak via a retain cycle (see code below).
The bug is the parent property in ChildObject class. It is strong and thus causes a retain cycle. It should be weak of course.
In Xcode, using the memory graph view:
Click on the leaked object and it's clearly displayed. This is great. (BTW - Is there a way to add figures to forum posts?)
Click on the current child object, and you can trace how it is allocated
Note - it only shows the forward references. The WWDC presenter says something along the lines of (I forget his exact words) this shows how an object came to exist.
However, what would be very powerful is the ability to see all the references, and specifically in this case, the reverse reference from the ChildObject back to the ParentObject.
Question: Is there anyway to also view the reverse references (i.e. display a full object tree with all live references?)
Given that ARC inserts all the necessary retains / releases, I wonder if this information could be made visible?
(I assume not as I'm guessing this tool monitors all malloc calls, unless I'm missing something?)
Code
import UIKit
class ParentObject {
var child : ChildObject?
init() {
child = ChildObject(withParent: self)
print("Created a child object")
}
deinit {
print("Parent deallocating")
}
}
class ChildObject {
var parent : ParentObject?
init(withParent : ParentObject) {
parent = withParent
print("Child allocated")
}
deinit {
print("Child Deallocating")
}
}
class ViewController: UIViewController {
private var model : ParentObject?
override func viewDidLoad() {
super.viewDidLoad()
/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
@IBAction func doAlloc(_ sender: AnyObject) {
model = ParentObject()
}
@IBAction func doNil(_ sender: AnyObject) {
model = nil
}
}
As you noted, the memory graph debugger is intended to show what's keeping an item in memory, rather than what it's holding on to.
If you'd like to see that functionality added, I recommend filing an enhancement request at https://bugreport.apple.com/.