Search in sources :

Example 1 with THashMap

use of com.squareup.haha.trove.THashMap in project leakcanary by square.

the class HeapAnalyzer method deduplicateGcRoots.

/**
   * Pruning duplicates reduces memory pressure from hprof bloat added in Marshmallow.
   */
void deduplicateGcRoots(Snapshot snapshot) {
    // THashMap has a smaller memory footprint than HashMap.
    final THashMap<String, RootObj> uniqueRootMap = new THashMap<>();
    final Collection<RootObj> gcRoots = snapshot.getGCRoots();
    for (RootObj root : gcRoots) {
        String key = generateRootKey(root);
        if (!uniqueRootMap.containsKey(key)) {
            uniqueRootMap.put(key, root);
        }
    }
    // Repopulate snapshot with unique GC roots.
    gcRoots.clear();
    uniqueRootMap.forEach(new TObjectProcedure<String>() {

        @Override
        public boolean execute(String key) {
            return gcRoots.add(uniqueRootMap.get(key));
        }
    });
}
Also used : THashMap(com.squareup.haha.trove.THashMap) HahaHelper.fieldToString(com.squareup.leakcanary.HahaHelper.fieldToString) HahaHelper.asString(com.squareup.leakcanary.HahaHelper.asString) RootObj(com.squareup.haha.perflib.RootObj)

Aggregations

RootObj (com.squareup.haha.perflib.RootObj)1 THashMap (com.squareup.haha.trove.THashMap)1 HahaHelper.asString (com.squareup.leakcanary.HahaHelper.asString)1 HahaHelper.fieldToString (com.squareup.leakcanary.HahaHelper.fieldToString)1