package Ġleak can ary . internal Ċ Ċ import Ġandroid . app . Instrumentation Ċ import Ġandroid . os . System Clock Ċ import Ġandroidx . test . platform . app . Instrumentation Registry Ċ import Ġleak can ary . App Watcher Ċ import Ġleak can ary . Gc Trigger . Default Ċ import Ġleak can ary . Key ed Weak Reference Ċ import Ġleak can ary . Object Watcher Ċ import Ġleak can ary . internal . Ret ained Objects Instrumentation Checker . Yes No . No Ċ import Ġleak can ary . internal . Ret ained Objects Instrumentation Checker . Yes No . Yes Ċ Ċ internal Ġclass ĠRet ained Objects Instrumentation Checker ( ĊĠ Ġprivate Ġval Ġinstrument ation : ĠInstrument ation Ġ= ĠInstrument ation Registry . get Instrumentation (), ĊĠ Ġprivate Ġval Ġobject Watcher : ĠObject Watcher Ġ= ĠApp Watcher . object Watcher , ĊĠ Ġprivate Ġval Ġretained Delay Millis : ĠLong Ġ= ĠApp Watcher . ret ained Delay Millis Ċ ) Ġ{ ĊĊĠ Ġsealed Ġclass ĠYes No Ġ{ ĊĠĠĠ Ġobject ĠYes Ġ: ĠYes No () ĊĠĠĠ Ġclass ĠNo ( val Ġreason : ĠString ) Ġ: ĠYes No () ĊĠ Ġ} ĊĊĠ Ġ@ Suppress (" Return Count ") ĊĠ Ġfun Ġshould Dump Heap Waiting For Ret ained Objects (): ĠYes No Ġ{ ĊĠĠĠ Ġval Ġleak Detection Time Ġ= ĠSystem Clock . uptime Millis () ĊĊĠĠĠ Ġif Ġ(! object Watcher . has W atched Objects ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĠNo (" No Ġw atched Ġobjects .") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinstrument ation . waitFor Idle Sync () ĊĠĠĠ Ġif Ġ(! object Watcher . has W atched Objects ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĠNo (" No Ġw atched Ġobjects Ġafter Ġwaiting Ġfor Ġidle Ġsync .") ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠDefault . run Gc () ĊĠĠĠ Ġif Ġ(! object Watcher . has W atched Objects ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĠNo (" No Ġw atched Ġobjects Ġafter Ġtriggering Ġan Ġexplicit ĠGC .") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠWaiting Ġfor Ġany Ġdelayed ĠUI Ġpost Ġ( e . g . Ġscroll ) Ġto Ġclear . ĠThis Ġshouldn 't Ġbe Ġneeded , Ġbut ĊĠĠĠ Ġ// ĠAndroid Ġsimply Ġhas Ġway Ġtoo Ġmany Ġdelayed Ġposts Ġthat Ġaren 't Ġcanceled Ġwhen Ġviews Ġare Ġdet ached . ĊĠĠĠ ĠSystem Clock . sleep ( 2 0 0 0 ) ĊĊĠĠĠ Ġif Ġ(! object Watcher . has W atched Objects ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĠNo (" No Ġw atched Ġobjects Ġafter Ġdelayed ĠUI Ġpost Ġis Ġcleared .") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠA a and Ġwe Ġwait Ġsome Ġmore . ĊĠĠĠ Ġ// Ġ 4 Ġseconds Ġ( 2 + 2 ) Ġis Ġgreater Ġthan Ġthe Ġ 3 Ġseconds Ġdelay Ġfor ĊĠĠĠ Ġ// ĠFIN ISH _ TOKEN Ġin Ġandroid . widget . Filter ĊĠĠĠ ĠSystem Clock . sleep ( 2 0 0 0 ) ĊĊĠĠĠ Ġval Ġend Of Watch Delay Ġ= Ġretained Delay Millis Ġ- Ġ( System Clock . uptime Millis () Ġ- Ġleak Detection Time ) ĊĠĠĠ Ġif Ġ( end Of Watch Delay Ġ> Ġ 0 ) Ġ{ ĊĠĠĠĠĠ ĠSystem Clock . sleep ( end Of Watch Delay ) ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠDefault . run Gc () ĊĊĠĠĠ Ġif Ġ(! object Watcher . has Ret ained Objects ) Ġ{ ĊĠĠĠĠĠ Ġreturn ĠNo (" No Ġretained Ġobjects Ġafter Ġwaiting Ġfor Ġretained Ġdelay .") ĊĠĠĠ Ġ} ĊĠĠĠ ĠKey ed Weak Reference . heap Dump U ptime Millis Ġ= ĠSystem Clock . uptime Millis () ĊĠĠĠ Ġreturn ĠYes ĊĠ Ġ} ĊĊĠ Ġfun Ġclear Objects W atched Before Heap Dump () Ġ{ ĊĠĠĠ Ġval Ġheap Dump U ptime Millis Ġ= ĠKey ed Weak Reference . heap Dump U ptime Millis ĊĠĠĠ Ġobject Watcher . clear Objects W atched Before ( heap Dump U ptime Millis ) ĊĠ Ġ} Ċ } Ċ