                         toScan.insert(newEntry, atIndex: 0)
                     }
                 }
-                
-                print("\(pad(memory.buffer.count, 5)) bytes ")
-                print(memory.isMalloc ? "<malloc> " : "<unknwn> ")
-                
-                print(limit(memory.hex(), 67))
-                
-                if let objCClass = classMap[entry.address] {
-                    print(" ObjC class \(objCClass.name)")
-                }
-                
-                let strings = memory.scanStrings()
-                if strings.count > 0 {
-                    print(" -- strings: (")
-                    print(", ".join(strings))
-                    print(")")
-                }
-                println()
-            }
-        }
-    }
-    println("==========")
+            }
+        }
+        return results[firstAddr]!
+    }
 }
 
 

            
            if memory {
                count++
                if let parent = entry.parent {
                    print("(")
                    print(entryColor(parent).wrap("\(pad(parent.index, 3)), \(formatPointer(parent.address))@\(pad(entry.parentOffset, 3, align: .Left))"))
                    print(") <- ")
                } else {
                    print("                                 ")
                }
                
                print(entryColor(entry).wrap("\(pad(entry.index, 3)) \(formatPointer(entry.address))"))
                print(": ")
                let pointersAndOffsets = memory.scanPointers()
                for pointerAndOffset in pointersAndOffsets {
                    let pointer = pointerAndOffset.pointer

//    println("\(formatPointer(addr)) \(objCClass.name)")
//}

class ScanResult {
    let entry: ScanEntry
    let parent: ScanResult?
    let memory: Memory
    var children = ScanResult[]()
    
    init(entry: ScanEntry, parent: ScanResult?, memory: Memory) {
        self.entry = entry
        self.parent = parent
        self.memory = memory
    }
    
    func entryColor(entry: ScanEntry) -> Term {
        let entryColors: Term[] = [ .Red, .Green, .Yellow, .Blue, .Magenta, .Cyan ]
        return entryColors[entry.index % entryColors.count]
    }
    
    func dump() {
        if let parent = entry.parent {
            print("(")
            print(entryColor(parent).wrap("\(pad(parent.index, 3)), \(formatPointer(parent.address))@\(pad(entry.parentOffset, 3, align: .Left))"))
            print(") <- ")
        } else {
            print("                                 ")
        }
        
        print(entryColor(entry).wrap("\(pad(entry.index, 3)) \(formatPointer(entry.address))"))
        print(": ")
        
        print("\(pad(memory.buffer.count, 5)) bytes ")
        print(memory.isMalloc ? "<malloc> " : "<unknwn> ")
        
        print(limit(memory.hex(), 67))
        
        if let objCClass = classMap[entry.address] {
            print(" ObjC class \(objCClass.name)")
        }
        
        let strings = memory.scanStrings()
        if strings.count > 0 {
            print(" -- strings: (")
            print(", ".join(strings))
            print(")")
        }
        println()
    }
    
    func recursiveDump() {
        var chain = [self]
        while chain.count > 0 {
            let result = chain.removeLast()
            result.dump()
            for child in result.children {
                chain.append(child)
            }
        }
    }
}

func dumpmem<T>(var x: T) -> ScanResult {
    var count = 0
    var seen = Dictionary<UInt, Bool>()
    var toScan = Array<ScanEntry>()
    
    var results = Dictionary<UInt, ScanResult>()
    
    return withUnsafePointer(&x) {
        (ptr: UnsafePointer<T>) -> ScanResult in
        
        let firstAddr: UInt = reinterpretCast(ptr)
        let firstEntry = ScanEntry(parent: nil, parentOffset: 0, address: firstAddr, index: 0)
