private bool ShouldAddToGraph(MemoryNode memNode, NodeType nodeType)
        {
            if (memNode.Address == 0 && !nodeType.Name.StartsWith("[static var "))
            {
                return(true);
            }

            int gen = _HeapInfo.GenerationFor(memNode.Address);

            if (gen >= 0 && gen <= _GenerationToCondemn)
            {
                return(true);
            }

            // Check my children.
            Node nodeStorage = _OriginalMemoryGraph.AllocNodeStorage();

            for (NodeIndex nodeIndex = memNode.GetFirstChildIndex(); nodeIndex != NodeIndex.Invalid; nodeIndex = memNode.GetNextChildIndex())
            {
                MemoryNode currentNode = (MemoryNode)_OriginalMemoryGraph.GetNode(nodeIndex, nodeStorage);

                if (currentNode.Address == 0)
                {
                    return(true);
                }

                gen = _HeapInfo.GenerationFor(currentNode.Address);
                if (gen >= 0 && gen <= _GenerationToCondemn)
                {
                    return(true);
                }
            }

            return(false);
        }
        private void VisitNode(MemoryNode currentNode)
        {
            MemoryNode oldMemNode = currentNode;

            // Get the generation for the current node.
            int generation = _HeapInfo.GenerationFor(oldMemNode.Address);

            // Create a MemoryNodeBuilder for the new graph that represents the current node
            // unless the current node is the root, as we've already created one.
            MemoryNodeBuilder newMemNodeBuilder = null;

            if (currentNode.Index == _OriginalMemoryGraph.RootIndex)
            {
                newMemNodeBuilder = _RootNode;
            }
            else
            {
                // Get the parent node.
                MemoryNodeBuilder parentMemNodeBuilder = null;
                if ((oldMemNode.Address != 0) && (generation > _GenerationToCondemn))
                {
                    if (generation == 1)
                    {
                        parentMemNodeBuilder = _Gen1RootNode;
                    }
                    else
                    {
                        parentMemNodeBuilder = _Gen2RootNode;
                    }
                }
                else
                {
                    parentMemNodeBuilder = _OldNodeToNewParentMap[(int)currentNode.Index];
                }

                if (parentMemNodeBuilder == null)
                {
                    parentMemNodeBuilder = _UnknownRootNode;
                }

                // Get the current node's type and object address.
                NodeType nodeType = _OriginalMemoryGraph.GetType(oldMemNode.TypeIndex, _OldNodeTypeStorage);

                // Create the new generation aware type name.
                string typeName = null;
                if (oldMemNode.Address != 0 && generation >= 0)
                {
                    if (generation == 3)
                    {
                        typeName = string.Format("LOH: {0}", nodeType.Name);
                    }
                    else
                    {
                        typeName = string.Format("Gen{0}: {1}", generation, nodeType.Name);
                    }
                }
                else
                {
                    if (oldMemNode.Address != 0)
                    {
                        _Log.WriteLine(string.Format("Generation: {0}; Address: {1}; Type: {2}", generation, oldMemNode.Address, nodeType.Name));
                    }
                    typeName = nodeType.Name;
                }

                // Create the new node.
                if (ShouldAddToGraph(oldMemNode, nodeType))
                {
                    if (oldMemNode.Address == 0)
                    {
                        newMemNodeBuilder = parentMemNodeBuilder.FindOrCreateChild(typeName);
                    }
                    else
                    {
                        NodeIndex newNodeIndex = _NewMemoryGraph.GetNodeIndex(oldMemNode.Address);
                        newMemNodeBuilder = new MemoryNodeBuilder(_NewMemoryGraph, typeName, null, newNodeIndex);

                        parentMemNodeBuilder.AddChild(newMemNodeBuilder);

                        // Set the object size.
                        if (generation <= _GenerationToCondemn)
                        {
                            newMemNodeBuilder.Size = oldMemNode.Size;
                        }
                        else
                        {
                            _Log.WriteLine("Ignoring Object Size: " + typeName);
                        }
                    }
                }
            }

            // Associate all children of the current node with this object's new MemoryNodeBuilder.
            for (NodeIndex childIndex = oldMemNode.GetFirstChildIndex(); childIndex != NodeIndex.Invalid; childIndex = oldMemNode.GetNextChildIndex())
            {
                _OldNodeToNewParentMap[(int)childIndex] = newMemNodeBuilder;
            }
        }