// Returns all objects being kept alive by the input object // Based off the code at https://github.com/Microsoft/clrmd/blob/master/Documentation/WalkingTheHeap.md public static List <ulong> GetReferencedObjects(ClrHeap heap, ulong obj) { List <ulong> references = new List <ulong>(); Stack <ulong> eval = new Stack <ulong>(); HashSet <ulong> considered = new HashSet <ulong>(); eval.Push(obj); while (eval.Count > 0) { obj = eval.Pop(); if (considered.Contains(obj)) { continue; } considered.Add(obj); // Grab the type. We will only get null here in the case of heap corruption. ClrType type = heap.GetObjectType(obj); if (type == null) { continue; } references.Add(obj); // Now enumerate all objects that this object points to, add them to the // evaluation stack if we haven't seen them before. type.EnumerateRefsOfObjectCarefully(obj, delegate(ulong child, int offset) { if (child != 0 && !considered.Contains(child)) { eval.Push(child); } }); } return(references); }
public override void EnumerateRefsOfObjectCarefully(ulong objRef, Action <ulong, int> action) // TODO GET HELP { ClrType realType = DesktopHeap.GetObjectType(objRef); realType.EnumerateRefsOfObjectCarefully(objRef, action); }
/// <summary> /// Does the same as EnumerateRefsOfObject, but does additional bounds checking to ensure /// we don't loop forever with inconsistent data. /// </summary> /// <param name="objRef">The object reference.</param> /// <param name="action">The action.</param> public void EnumerateRefsOfObjectCarefully(ulong objRef, Action <ulong, int> action) { ClrType.EnumerateRefsOfObjectCarefully(objRef, action); }
private void CollectChildren(ClrType type, ulong address) { type.EnumerateRefsOfObjectCarefully(address, CollectChild); }
public void EnumerateReferences(Action <ulong, int> action) { Type.EnumerateRefsOfObjectCarefully(Address, action); }