public final class AnalysisResult
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
long |
analysisDurationMs
Total time spent analyzing the heap.
|
java.lang.String |
className
Class name of the object that leaked if
leakFound is true, null otherwise. |
boolean |
excludedLeak
True if
leakFound is true and the only path to the leaking reference is
through excluded references. |
java.lang.Throwable |
failure
Null unless the analysis failed.
|
boolean |
leakFound
True if a leak was found in the heap dump.
|
LeakTrace |
leakTrace
Shortest path to GC roots for the leaking object if
leakFound is true, null
otherwise. |
static long |
RETAINED_HEAP_SKIPPED |
long |
retainedHeapSize
The number of bytes which would be freed if all references to the leaking object were
released.
|
| Modifier and Type | Method and Description |
|---|---|
static AnalysisResult |
failure(java.lang.Throwable failure,
long analysisDurationMs) |
static AnalysisResult |
leakDetected(boolean excludedLeak,
java.lang.String className,
LeakTrace leakTrace,
long retainedHeapSize,
long analysisDurationMs) |
java.lang.RuntimeException |
leakTraceAsFakeException()
Creates a new
RuntimeException with a fake stack trace that maps the leak trace. |
static AnalysisResult |
noLeak(long analysisDurationMs) |
public static final long RETAINED_HEAP_SKIPPED
public final boolean leakFound
public final boolean excludedLeak
leakFound is true and the only path to the leaking reference is
through excluded references. Usually, that means you can safely ignore this report.@Nullable public final java.lang.String className
leakFound is true, null otherwise.
The class name format is the same as what would be returned by Class.getName().@Nullable public final LeakTrace leakTrace
leakFound is true, null
otherwise. This can be used as a unique signature for the leak.@Nullable public final java.lang.Throwable failure
public final long retainedHeapSize
RETAINED_HEAP_SKIPPED if the retained heap size was not computed. 0 if
leakFound is false.public final long analysisDurationMs
@NonNull public static AnalysisResult noLeak(long analysisDurationMs)
@NonNull public static AnalysisResult leakDetected(boolean excludedLeak, @NonNull java.lang.String className, @NonNull LeakTrace leakTrace, long retainedHeapSize, long analysisDurationMs)
@NonNull public static AnalysisResult failure(@NonNull java.lang.Throwable failure, long analysisDurationMs)
@NonNull public java.lang.RuntimeException leakTraceAsFakeException()
Creates a new RuntimeException with a fake stack trace that maps the leak trace.
Leak traces uniquely identify memory leaks, much like stack traces uniquely identify exceptions.
This method enables you to upload leak traces as stack traces to your preferred exception reporting tool and benefit from the grouping and counting these tools provide out of the box. This also means you can track all leaks instead of relying on individuals reporting them when they happen.
The following example leak trace:
* com.foo.WibbleActivity has leaked: * GC ROOT static com.foo.Bar.qux * references com.foo.Quz.context * leaks com.foo.WibbleActivity instance
Will turn into an exception with the following stacktrace:
java.lang.RuntimeException: com.foo.WibbleActivity leak from com.foo.Bar (holder=CLASS,
type=STATIC_FIELD)
at com.foo.Bar.qux(Bar.java:42)
at com.foo.Quz.context(Quz.java:42)
at com.foo.WibbleActivity.leaking(WibbleActivity.java:42)