Keep track of a Throwable if custom LeakTracker is set

Summary:
This makes it easier to track down leaks as we currently only have their class names. There are some limitations if this is creates on a separate thread, but that can be addressed separately.

This does require temporarily removing the Flipper integration as the interface changes in a backwards-incompatible manner. This will be restored with the next diff in the stack.

Reviewed By: oprisnik

Differential Revision: D15760947

fbshipit-source-id: 3a5c48f6244f1afc8b7e00230bd1ae2f197e6cdf
This commit is contained in:
Pascal Hartig
2019-06-13 04:09:50 -07:00
committed by Facebook Github Bot
parent f2986f8a2f
commit fd89d73be5

View File

@@ -13,7 +13,6 @@ import com.facebook.common.internal.Predicate;
import com.facebook.common.memory.manager.DebugMemoryManager;
import com.facebook.common.memory.manager.NoOpDebugMemoryManager;
import com.facebook.common.references.CloseableReference;
import com.facebook.common.references.SharedReference;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.info.ImageLoadStatus;
import com.facebook.drawee.backends.pipeline.info.ImageOriginUtils;
@@ -48,8 +47,7 @@ import javax.annotation.Nullable;
* Allows Sonar to display the contents of Fresco's caches. This is useful for developers to debug
* what images are being held in cache as they navigate through their app.
*/
public class FrescoFlipperPlugin extends BufferingFlipperPlugin
implements ImagePerfDataListener, CloseableReferenceLeakTracker.Listener {
public class FrescoFlipperPlugin extends BufferingFlipperPlugin implements ImagePerfDataListener {
private static final String FRESCO_EVENT = "events";
private static final String FRESCO_DEBUGOVERLAY_EVENT = "debug_overlay_event";
@@ -95,10 +93,6 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
mMemoryManager = memoryManager;
mPerfLogger = perfLogger;
mDebugPrefHelper = debugPrefHelper;
if (closeableReferenceLeakTracker != null) {
closeableReferenceLeakTracker.setListener(this);
}
}
public FrescoFlipperPlugin() {
@@ -513,13 +507,4 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
private static void respondError(FlipperResponder responder, String errorReason) {
responder.error(new FlipperObject.Builder().put("reason", errorReason).build());
}
@Override
public void onCloseableReferenceLeak(SharedReference<Object> reference) {
final FlipperObject.Builder builder =
new FlipperObject.Builder()
.put("identityHashCode", System.identityHashCode(reference))
.put("className", reference.get().getClass().getName());
send(FRESCO_CLOSEABLE_REFERENCE_LEAK_EVENT, builder.build());
}
}