/** Can be overridden to customize the failure string message. */ protected @NonNull String buildLeakDetectedMessage( @NonNull List<InstrumentationLeakResults.Result> detectedLeaks) { StringBuilder failureMessage = new StringBuilder(); failureMessage.append( "Test failed because memory leaks were detected, see leak traces below.\n"); failureMessage.append(SEPARATOR); Context context = getInstrumentation().getContext(); for (InstrumentationLeakResults.Result detectedLeak : detectedLeaks) { failureMessage.append( LeakCanary.leakInfo(context, detectedLeak.heapDump, detectedLeak.analysisResult, true)); failureMessage.append(SEPARATOR); } return failureMessage.toString(); } }
void shareLeak() { AnalyzedHeap visibleLeak = getVisibleLeak(); String leakInfo = leakInfo(this, visibleLeak.heapDump, visibleLeak.result, true); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, leakInfo); startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with))); }
private String resultsAsString(List<InstrumentationLeakResults.Result> results) { Context context = InstrumentationRegistry.getTargetContext(); StringBuilder message = new StringBuilder(); message.append("\nLeaks found:\n##################\n"); for (InstrumentationLeakResults.Result detectedLeak : results) { message.append( LeakCanary.leakInfo(context, detectedLeak.heapDump, detectedLeak.analysisResult, false)); } message.append("\n##################\n"); return message.toString(); } }
AnalysisResult result = analyzedHeap.result; String leakInfo = leakInfo(this, heapDump, result, true); CanaryLog.d("%s", leakInfo);
private void shareLeak() { Leak visibleLeak = getVisibleLeak(); String leakInfo = leakInfo(this, visibleLeak.heapDump, visibleLeak.result); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, leakInfo); startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with))); }
@TargetApi(HONEYCOMB) @Override protected final void onHeapAnalyzed(HeapDump heapDump, AnalysisResult result) { String leakInfo = leakInfo(this, heapDump, result); Log.d("LeakCanary", leakInfo);