Example #1
0
        protected override void OnBuildTree(TreeViewItem root)
        {
            progress.value = 0;

            var lookup       = new Dictionary <Hash128, AbstractItem>();
            var memoryReader = new MemoryReader(m_Snapshot);

            for (int n = 0, nend = m_Snapshot.managedObjects.Length; n < nend; ++n)
            {
                progress.value = (n + 1.0f) / nend;

                var obj = m_Snapshot.managedObjects[n];
                if (obj.address == 0)
                {
                    continue;
                }

                var type = m_Snapshot.managedTypes[obj.managedTypesArrayIndex];
                if (type.isPrimitive && !type.isPointer)
                {
                    continue;
                }

                if (type.isValueType)
                {
                    continue;
                }

                var hash = memoryReader.ComputeObjectHash(obj.address, type);

                AbstractItem parent;
                if (!lookup.TryGetValue(hash, out parent))
                {
                    var group = new GroupItem()
                    {
                        id          = m_UniqueId++,
                        depth       = root.depth + 1,
                        displayName = ""
                    };
                    group.Initialize(m_Snapshot, type);

                    lookup[hash] = parent = group;
                    root.AddChild(group);
                }

                var item = new ManagedObjectItem
                {
                    id          = m_UniqueId++,
                    depth       = parent.depth + 1,
                    displayName = ""
                };
                item.Initialize(this, m_Snapshot, obj);
                parent.AddChild(item);
            }

            if (root.hasChildren)
            {
                for (var n = root.children.Count - 1; n >= 0; --n)
                {
                    if (!root.children[n].hasChildren)
                    {
                        root.children.RemoveAt(n);
                        continue;
                    }

                    if (root.children[n].children.Count < 2)
                    {
                        root.children.RemoveAt(n);
                        continue;
                    }

                    var item = root.children[n] as AbstractItem;
                    m_ManagedObjectCount += item.count;
                    m_ManagedObjectSize  += item.size;
                }
            }

            progress.value = 1;
        }