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
This commit is contained in:
Benjamin Pankow
2018-08-02 10:20:16 -07:00
committed by Facebook Github Bot
parent ff0b045bde
commit 1008dbb283
6 changed files with 501 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
---
id: leak-canary-plugin
title: LeakCanary
---
The LeakCanary plugin provides developers with Sonar support for [LeakCanary](https://github.com/square/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:
```java
import com.facebook.sonar.plugins.leakcanary.LeakCanarySonarPlugin;
client.addPlugin(new LeakCanarySonarPlugin());
```
Next, build a custom RefWatcher using RecordLeakService: (see [LeakCanary docs](https://github.com/square/leakcanary/wiki/Customizing-LeakCanary#uploading-to-a-server) for more information on RefWatcher)
```java
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.