Skip to content

Instantly share code, notes, and snippets.

View ali-star's full-sized avatar
🕵️

Ali Mohseni Rad ali-star

🕵️
View GitHub Profile
@ali-star
ali-star / DebugApp.kt
Created June 14, 2024 12:29
Upload the leaks to Firebase
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())
}
@ali-star
ali-star / DebugApp.kt
Last active June 14, 2024 12:27
LeakCanary EventListener
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")
}
}
@ali-star
ali-star / LeakExtensions.kt
Created June 14, 2024 12:17
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 {