Memory Graph in Xcode 8 (Beta 2)

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
    }
}
Answered by kem in 151717022

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/.

Accepted Answer

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/.

Hi


I've now done that, and it's come back as a duplicate (which is a good thing of course).


Regards


Nick

I've also reported a bug (again, marked as duplicate) where a leak caused by a closure referencing self (without a capture list). You can see a leak clearly occurs, but it's not detected as a run-time error. It's all pre-release software of course - however, this promises to be such a great feature, and one of technical highlights of WWDC 2016 (for me at least).

Memory Graph in Xcode 8 (Beta 2)
 
 
Q