public static HeapTypeStatisticsCollection operator -(
            HeapTypeStatisticsCollection first, HeapTypeStatisticsCollection second)
        {
            HeapTypeStatisticsCollection result;

            if ((first == null) && (second == null))
            {
                return(null);
            }

            if ((first == null) || (second == null))
            {
                if (first == null)
                {
                    result = second.Clone() as HeapTypeStatisticsCollection;
                    if (result == null)
                    {
                        return(null); // never happens
                    }

                    result.ChangeSizeSign();
                    return(result);
                }

                return(first);
            }

            result = new HeapTypeStatisticsCollection();

            foreach (HeapTypeStatisticsEntry typeStatInFirst in first)
            {
                HeapTypeStatisticsEntry sameTypeInSecond = second[typeStatInFirst.MT];
                result.AddOrMerge(typeStatInFirst - sameTypeInSecond);
            }

            // Add non existing in first as negative to result
            foreach (HeapTypeStatisticsEntry tpSecondStat in second)
            {
                HeapTypeStatisticsEntry val = result[tpSecondStat.MT];
                if (val != null) // value already exists.
                {
                    continue;
                }

                val = tpSecondStat.Clone() as HeapTypeStatisticsEntry;
                if (val == null)
                {
                    continue;
                }

                val.ChangeTotalSizeSign();
                result.AddOrMerge(val);
            }

            return(result);
        }
        public static void EnumerateObjectsInHeapByType(
            [NotNull] ClrRuntime rn,
            out HeapTypeStatisticsCollection allObjStatByType,
            out HeapTypeStatisticsCollection liveObjStatByType)
        {
            var instance = new LiveDeadObjectByTypes(rn);

            instance.CalculateHeapStatsByType();

            allObjStatByType = instance.AllObjStatByType;

            liveObjStatByType = instance.LiveObjStatsByType;
        }
        public LiveDeadObjectByTypes([NotNull] ClrRuntime runtime)
        {
            Assert.ArgumentNotNull(runtime, "runtime");

            this.Runtime = runtime;

            this.LiveObjStatsByType = new HeapTypeStatisticsCollection();

            this.AllObjStatByType = new HeapTypeStatisticsCollection();

            this.AliveObjectsByType = new Dictionary <string, HashSet <ulong> >(10000);

            this.AliveObjectAdresses = new HashSet <ulong>();
        }
        public object Clone()
        {
            var result = new HeapTypeStatisticsCollection();

            IEnumerable <HeapTypeStatisticsEntry> clonedValues = from keyPair in typeStats
                                                                 let sourceTypeStat = keyPair.Value.Clone() as HeapTypeStatisticsEntry
                                                                                      where sourceTypeStat != null
                                                                                      select sourceTypeStat;

            foreach (HeapTypeStatisticsEntry heapTypeStatisticsEntry in clonedValues)
            {
                result.typeStats.Add(heapTypeStatisticsEntry.MT, heapTypeStatisticsEntry);
            }

            return(result);
        }
 private void AddUsage(HeapTypeStatisticsCollection collection, HeapTypeStatisticsEntry candidate)
 {
     Assert.ArgumentNotNull(collection, "collection");
     Assert.ArgumentNotNull(candidate, "candidate");
     collection.AddOrMerge(candidate);
 }
 private void AddUsage(HeapTypeStatisticsCollection collection, ulong objectReference, ClrType tp)
 {
     Assert.ArgumentNotNull(collection, "collection");
     Assert.ArgumentNotNull(tp, "type");
     collection.Add(objectReference, tp);
 }