You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I implemented a IdleHandler to do someting for my HandlerThread, but I see the IdleHandler runs every second. According to the code in AndroidLeakFixes.FLUSH_HANDLER_THREADS, it adds an IdleHandler and postDelayed({}, 1000), so that cause my IdleHandler to be executed per second, is it a potential bug? If it is an intended behavior, how to stop it from affecting my logic ? I don't want to execute my IdleHandler every second.
The text was updated successfully, but these errors were encountered:
* HandlerThread instances keep local reference to their last handled message after recycling it.
* That message is obtained by a dialog which sets on an OnClickListener on it and then never
* recycles it, expecting it to be garbage collected but it ends up being held by the
* HandlerThread.
*/
FLUSH_HANDLER_THREADS {
The core issue is that any idle Handler thread will keep a strong reference to the last message that ran, but that message will also be recycled, then accidentally used by a dialog to store some OnClickListener in its callback field, and that field will not be cleared after the dialog is destroyed, so the idle handler will end up keeping a strong reference to on click listeners of destroyed dialogs.
I haven't found any better fix than making sure HandlerThreads aren't ever idle for too long.
Description
I implemented a IdleHandler to do someting for my HandlerThread, but I see the IdleHandler runs every second. According to the code in
AndroidLeakFixes.FLUSH_HANDLER_THREADS
, it adds an IdleHandler andpostDelayed({}, 1000)
, so that cause my IdleHandler to be executed per second, is it a potential bug? If it is an intended behavior, how to stop it from affecting my logic ? I don't want to execute my IdleHandler every second.The text was updated successfully, but these errors were encountered: