0 Replies
      Latest reply on Dec 2, 2019 9:46 AM by mildeseven2017
      mildeseven2017 Level 1 Level 1 (0 points)

        I'm using the "Leaks" with the Instrument for my macOS app. However always I'm getting different results.


        Here is my sample code.

        import Cocoa
        class TreeNode {
            var name: String
            var children = [TreeNode]()
            weak var parent: TreeNode?
            init(name: String) {
                self.name = name
            func add(child: TreeNode) {
                parent = self
        class ViewController: NSViewController {
            let treeNode: TreeNode = TreeNode(name: "root")
            override func viewDidLoad() {
                let treeNode1 = TreeNode(name: "One")
                treeNode.add(child: treeNode1)


        This is very simple app "ViewController" hold own variable called "treeNode".  The Instrument sometime shows the variable never released.

        My system is Caterlna and Xcode 11.2.1.


        Here is the copy from "Stack Trace"

           0 libsystem_malloc.dylib malloc_zone_malloc

        --- 2 frames omitted ---

           3 libswiftCore.dylib _swift_allocObject_(swift::TargetHeapMetadata<swift::InProcess> const*, unsigned long, unsigned long)

           4 MemoryLeakTest specialized _ContiguousArrayBuffer.init(_uninitializedCount:minimumCapacity:)

           5 MemoryLeakTest specialized Array._copyToNewBuffer(oldCount:)

           6 MemoryLeakTest ViewController.viewDidLoad()

           7 MemoryLeakTest @objc ViewController.viewDidLoad()

           8 AppKit -[NSViewController _sendViewDidLoad]