Skip to content

Instantly share code, notes, and snippets.

@ali-star
Created June 14, 2024 12:17
Show Gist options
  • Save ali-star/60aa0d7b4b30b423d5cc4a5dcf0e00b6 to your computer and use it in GitHub Desktop.
Save ali-star/60aa0d7b4b30b423d5cc4a5dcf0e00b6 to your computer and use it in GitHub Desktop.
An extension function to map the Leak class to Throwable
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 {
StackTraceElement(
/* declaringClass = */ "",
/* methodName = */ it,
/* fileName = */ "",
/* lineNumber = */ 0,
)
}
addAll(leakTrace)
}.toTypedArray()
stackTrace = stackTraceElements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment