1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 09:17:58 +00:00

Simplification

This commit is contained in:
M66B 2022-04-18 09:06:25 +02:00
parent bbe7184a55
commit 3cc9856daf

View file

@ -40,65 +40,38 @@ public class CoalMine {
static void setup(boolean enabled) { static void setup(boolean enabled) {
List<ObjectInspector> inspectors = new ArrayList<>(LeakCanary.getConfig().getObjectInspectors()); List<ObjectInspector> inspectors = new ArrayList<>(LeakCanary.getConfig().getObjectInspectors());
inspectors.add(new ObjectInspector() { // https://square.github.io/leakcanary/recipes/#identifying-leaking-objects-and-labeling-objects
@Override for (Class<?> clazz : new Class<?>[]{SimpleTask.class, TwoStateOwner.class, RunnableEx.class})
public void inspect(@NonNull ObjectReporter reporter) { inspectors.add(new ObjectInspector() {
String clazz = SimpleTask.class.getName(); @Override
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() { public void inspect(@NonNull ObjectReporter reporter) {
@Override String className = clazz.getName();
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) { reporter.whenInstanceOf(className, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
HeapField fname = instance.get(clazz, "name"); @Override
if (fname != null) { public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
String name = fname.getValue().readAsJavaString(); HeapField hfName = instance.get(className, "name");
reporter.getNotLeakingReasons().add("name=" + name); if (hfName != null) {
} String label = hfName.getValue().readAsJavaString();
HeapField fstarted = instance.get(clazz, "started"); reporter.getLabels().add("name=" + label);
if (fstarted != null) { }
Long started = fstarted.getValue().getAsLong();
if (started != null)
reporter.getNotLeakingReasons().add("started=" + new Date(started));
}
return null;
}
});
}
});
inspectors.add(new ObjectInspector() { // Could be different class loader
@Override if (className.equals(SimpleTask.class.getName())) {
public void inspect(@NonNull ObjectReporter reporter) { HeapField hfStarted = instance.get(className, "started");
String clazz = TwoStateOwner.class.getName(); if (hfStarted != null) {
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() { Long started = hfStarted.getValue().getAsLong();
@Override if (started != null) {
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) { String label = (started == 0 ? null : new Date(started).toString());
HeapField fname = instance.get(clazz, "name"); reporter.getLabels().add("started=" + label);
if (fname != null) { }
String name = fname.getValue().readAsJavaString(); }
reporter.getNotLeakingReasons().add("name=" + name); }
}
return null;
}
});
}
});
inspectors.add(new ObjectInspector() { return null;
@Override
public void inspect(@NonNull ObjectReporter reporter) {
String clazz = RunnableEx.class.getName();
reporter.whenInstanceOf(clazz, new Function2<ObjectReporter, HeapObject.HeapInstance, Unit>() {
@Override
public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) {
HeapField fname = instance.get(clazz, "name");
if (fname != null) {
String name = fname.getValue().readAsJavaString();
reporter.getNotLeakingReasons().add("name=" + name);
} }
return null; });
} }
}); });
}
});
LeakCanary.Config config = LeakCanary.getConfig().newBuilder() LeakCanary.Config config = LeakCanary.getConfig().newBuilder()
.dumpHeap(enabled && BuildConfig.DEBUG) .dumpHeap(enabled && BuildConfig.DEBUG)