長生命周期引用短生命周期對象,gc來時(shí)短生命周期對象gc不可達(dá)。
mainthread 持有mainlooper持有msgqueue持有msg持有handlet持有activity。
1.gc來時(shí)msgqueue沒處理完。mainthread生命周期大于activity
2.activity 持有耗時(shí)leakthread? 持有handler持有activity。如果leakthread生命周期大于activity,產(chǎn)生泄露。
靜態(tài)的handler持有弱引用activity
如果沒有耗時(shí)線程也可以清空主線程關(guān)于handler的msg
退出時(shí)也可以停掉耗時(shí)線程。
5leakthread不要匿名初始化,通過handler通信