Square Corner Blog
Published in

Square Corner Blog

LeakCanary 1.6 🐤

We just released a new version of LeakCanary, and it’s got several new features!

Heads up, we’ve moved! If you’d like to continue keeping up with the latest technical content from Square please visit us at our new home https://developer.squareup.com/blog

Update your build.gradle

Highlight of the leak cause

By determining the expected reachability of objects like Activity and View instances, LeakCanary now highlights the possible causes of the leak with a red underline wave.

We also simplified the leak trace UI and added in context help.

This leak was caused by either MainActivity.httpRequestHelper or HttpRequestHelper.button

The leak analysis runs in a foreground service

The analysis service now runs as a foreground service to support Android O+, with a progress notification that should help everybody understand what LeakCanary is doing at any given point.

We also turned off computation of the retained heap size by default, to reduce the analysis time.

Analysis in progress

Leak detection in UI tests

At Square, we run UI tests on every pull request (using Firebase Test Lab), and we wanted to make sure we could prevent new memory leaks from being merged to master.

LeakCanary runs at the end of every UI test and reports a test failure if a leak is detected.

UI Test failure in Square POS, the leak cause is in red.

To set it up, see Running LeakCanary in instrumentation tests.

Reporting traces to a crash backend

We wanted to track leaks without having to build a backend. It turns out that leak traces are fairly similar to stack traces. AnalysisResult.leakTraceAsFakeException() enables you to upload leaks as fake stack traces to your preferred crash reporter. Here’s an example with Bugsnag:

replay(1).autoConnect() caused a leak

To set it up, see Uploading to a server.

Update LeakCanary

Here is the complete changelog, please give it a try and give us feedback!




Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Py ⚔

Py ⚔

Android baker @Square. Twitter account: @Piwai

More from Medium

Improving Pipeline Performance: Process Memory Allocation and DAG

Under the hood of the first insurance In-Car app

Kotlin Multiplatform: Static Library without Cocoapods

Improve scrolling performance of a ViewPager with complex layout Fragment items