Exemple #1
0
 private static void AccumulateReferences(object obj, Dictionary <object, MemoryTracker.ReferenceData> references, HashSet <object> seen, Queue <object> toProcess)
 {
     MemoryTracker.ReferenceData referenceData = null;
     if (!references.TryGetValue(obj, out referenceData))
     {
         referenceData   = new MemoryTracker.ReferenceData();
         references[obj] = referenceData;
     }
     foreach (MemoryTracker.ChildReference current in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(obj, MemoryTracker.GetFieldsFromHierarchy(obj.GetType(), BindingFlags.Instance), obj, string.Empty))
     {
         if (!current.child.GetType().IsClass)
         {
             throw new ApplicationException();
         }
         MemoryTracker.ReferenceData referenceData2 = null;
         if (!references.TryGetValue(current.child, out referenceData2))
         {
             referenceData2            = new MemoryTracker.ReferenceData();
             references[current.child] = referenceData2;
         }
         referenceData2.referredBy.Add(new MemoryTracker.ReferenceData.Link
         {
             target    = obj,
             targetRef = referenceData,
             path      = current.path
         });
         referenceData.refers.Add(new MemoryTracker.ReferenceData.Link
         {
             target    = current.child,
             targetRef = referenceData2,
             path      = current.path
         });
         if (!seen.Contains(current.child))
         {
             seen.Add(current.child);
             toProcess.Enqueue(current.child);
         }
     }
 }
Exemple #2
0
 private static void AccumulateStaticMembers(Type type, Dictionary <object, MemoryTracker.ReferenceData> references, HashSet <object> seen, Queue <object> toProcess)
 {
     foreach (MemoryTracker.ChildReference current in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(null, MemoryTracker.GetFields(type, BindingFlags.Static), null, type.ToString() + "."))
     {
         if (!current.child.GetType().IsClass)
         {
             throw new ApplicationException();
         }
         MemoryTracker.ReferenceData referenceData = null;
         if (!references.TryGetValue(current.child, out referenceData))
         {
             referenceData             = new MemoryTracker.ReferenceData();
             referenceData.path        = current.path;
             referenceData.pathCost    = 0;
             references[current.child] = referenceData;
         }
         if (!seen.Contains(current.child))
         {
             seen.Add(current.child);
             toProcess.Enqueue(current.child);
         }
     }
 }
Exemple #3
0
 private static void CalculateObjectReferencePath(object obj, Dictionary <object, MemoryTracker.ReferenceData> references, Queue <object> queue)
 {
     MemoryTracker.ReferenceData referenceData = references[obj];
     foreach (MemoryTracker.ReferenceData.Link current in referenceData.refers)
     {
         MemoryTracker.ReferenceData referenceData2 = references[current.target];
         string text = referenceData.path + "." + current.path;
         int    num  = referenceData.pathCost + 1;
         if (referenceData2.path.NullOrEmpty())
         {
             queue.Enqueue(current.target);
             referenceData2.path     = text;
             referenceData2.pathCost = num;
         }
         else if (referenceData2.pathCost == num && referenceData2.path.CompareTo(text) < 0)
         {
             referenceData2.path = text;
         }
         else if (referenceData2.pathCost > num)
         {
             throw new ApplicationException();
         }
     }
 }