Skip to content

Commit

Permalink
Merge branch 'binder_leak'
Browse files Browse the repository at this point in the history
* binder_leak:
  PR nits for square#351
  Add special case to ignore Binder leaks
  • Loading branch information
pyricau committed Jan 6, 2016
2 parents b30e9d5 + fe7b558 commit 2a04119
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/java/com/squareup/leakcanary/ExcludedRefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import static java.util.Collections.unmodifiableMap;

/**
* Prevents specific references from being taken into account when computing the shortest strong
* reference path from a suspected leaking instance to the GC roots.
* Prevents specific references from being taken into account when computing the shortest reference
* path from a suspected leaking instance to the GC roots.
*
* This class lets you ignore known memory leaks that you known about. If the shortest path
* This class lets you ignore known memory leaks that you know about. If the shortest path
* matches {@link ExcludedRefs}, than the heap analyzer should look for a longer path with nothing
* matching in {@link ExcludedRefs}.
*/
Expand All @@ -36,16 +36,19 @@ public final class ExcludedRefs implements Serializable {
public final Map<String, Map<String, Boolean>> staticFieldNameByClassName;
public final Map<String, Boolean> threadNames;
public final Map<String, Boolean> classNames;
public final Map<String, Boolean> rootSuperClassNames;

ExcludedRefs(Map<String, Map<String, Boolean>> fieldNameByClassName,
Map<String, Map<String, Boolean>> staticFieldNameByClassName,
Map<String, Boolean> threadNames, Map<String, Boolean> classNames) {
Map<String, Map<String, Boolean>> staticFieldNameByClassName,
Map<String, Boolean> threadNames, Map<String, Boolean> classNames,
Map<String, Boolean> rootSuperClassNames) {
// Copy + unmodifiable.
this.fieldNameByClassName = unmodifiableMap(new LinkedHashMap<>(fieldNameByClassName));
this.staticFieldNameByClassName =
unmodifiableMap(new LinkedHashMap<>(staticFieldNameByClassName));
this.threadNames = unmodifiableMap(new LinkedHashMap<>(threadNames));
this.classNames = unmodifiableMap(new LinkedHashMap<>(classNames));
this.rootSuperClassNames = unmodifiableMap(new LinkedHashMap<>(rootSuperClassNames));
}

@Override public String toString() {
Expand All @@ -72,6 +75,10 @@ public final class ExcludedRefs implements Serializable {
String always = clazz.getValue() ? " (always)" : "";
string += "| Class:" + clazz.getKey() + always + "\n";
}
for (Map.Entry<String, Boolean> clazz : rootSuperClassNames.entrySet()) {
String always = clazz.getValue() ? " (always)" : "";
string += "| Root Class:" + clazz.getKey() + always + "\n";
}
return string;
}

Expand All @@ -81,6 +88,7 @@ public static final class Builder {
new LinkedHashMap<>();
private final Map<String, Boolean> threadNames = new LinkedHashMap<>();
private final Map<String, Boolean> classNames = new LinkedHashMap<>();
private final Map<String, Boolean> rootSuperClassNames = new LinkedHashMap<>();

public Builder instanceField(String className, String fieldName) {
return instanceField(className, fieldName, false);
Expand Down Expand Up @@ -134,9 +142,20 @@ public Builder clazz(String className, boolean always) {
return this;
}

public Builder rootSuperClass(String rootSuperClassName) {
return rootSuperClass(rootSuperClassName, false);
}

/** Ignores any GC root that is a subclass of the provided class name. */
public Builder rootSuperClass(String rootSuperClassName, boolean always) {
checkNotNull(rootSuperClassName, "rootSuperClassName");
rootSuperClassNames.put(rootSuperClassName, always);
return this;
}

public ExcludedRefs build() {
return new ExcludedRefs(fieldNameByClassName, staticFieldNameByClassName, threadNames,
classNames);
classNames, rootSuperClassNames);
}
}
}

0 comments on commit 2a04119

Please sign in to comment.