Files
flipper/docs/leak-canary-plugin.md
Benjamin Pankow 1008dbb283 Create open source LeakCanary plugin
Summary: Adds a new plugin to support [LeakCanary](https://github.com/square/leakcanary), displaying memory leaks as they are detected. Each leak shows a hierarchical path from the GC root to the leaked object, and allows inspection of these objects' fields.

Reviewed By: jknoxville

Differential Revision: D8865149

fbshipit-source-id: 99bcf216578b9d6660ead7d48b9bafe0d20a6c08
2018-08-02 10:27:11 -07:00

1.1 KiB

id, title
id title
leak-canary-plugin LeakCanary

The LeakCanary plugin provides developers with Sonar support for LeakCanary, an open source memory leak detection library.

Setup

Note: this plugin is only available for Android.

Android

First, add the plugin to your Sonar client instance:

import com.facebook.sonar.plugins.leakcanary.LeakCanarySonarPlugin;

client.addPlugin(new LeakCanarySonarPlugin());

Next, build a custom RefWatcher using RecordLeakService: (see LeakCanary docs for more information on RefWatcher)

import com.facebook.sonar.plugins.leakcanary.RecordLeakService;

RefWatcher refWatcher = LeakCanary.refWatcher(this)
    .listenerServiceClass(RecordLeakService.class);
    .buildAndInstall();

Usage

Leaks detected by LeakCanary will appear automatically in Sonar. Each leak will display a hierarchy of objects, beginning from the garbage collector root and ending at the leaked class. Selecting any object in this list will display contents of the object's various fields.