This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DebugApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
val analysisUploadListener = EventListener { event -> | |
if (event is EventListener.Event.HeapAnalysisDone.HeapAnalysisSucceeded) { | |
val heapAnalysis = event.heapAnalysis | |
heapAnalysis.allLeaks.forEach { leak -> | |
Firebase.crashlytics.recordException(leak.toThrowable()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DebugApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
val analysisUploadListener = EventListener { event -> | |
if (event is EventListener.Event.HeapAnalysisDone.HeapAnalysisSucceeded) { | |
val heapAnalysis = event.heapAnalysis | |
TODO("Intercept leaks") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun Leak.toThrowable(): Throwable = Throwable("Memory Leak").apply { | |
val stackTraceElements = ArrayList<StackTraceElement>().apply { | |
val header = StackTraceElement( | |
/* declaringClass = */ "[MemoryLeak] $shortDescription", | |
/* methodName = */ "", | |
/* fileName = */ "", | |
/* lineNumber = */ 0, | |
) | |
add(header) | |
val leakTrace = leakTraces.toString().split("\n").map { |