farmerbb / Taskbar

PC-style productivity for Android
Apache License 2.0
833 stars 132 forks source link

Activity memory leak caused by anonymous threads #251

Open cuixiaoyiyi opened 2 years ago

cuixiaoyiyi commented 2 years ago

An anonymous inner class will hold a reference to the this pointer of the outer class and will not be released until the thread ends. It will hold the Activity and prevent its timely release.

com.farmerbb.taskbar.activity.PersistentShortcutSelectAppActivity :  onProgressChanged(...)
com.farmerbb.taskbar.activity.BackupRestoreActivity: void onCreate()

Besides, the while loop in the child thread should check the interrupt status of the thread, and the activity should interrupt the thread to end unnecessary loop execution before destroying it. The anonymous thread can be replaced by static class to eliminate unnecessary references.

NaNa2509 commented 1 year ago

คลาสภายในที่ไม่ระบุชื่อจะเก็บการอ้างอิงถึงตัวชี้ของคลาสภายนอกนี้ และจะไม่ถูกเผยแพร่จนกว่าเธรดจะสิ้นสุด มันจะระงับกิจกรรมและป้องกันไม่ให้ปล่อยตัวทันเวลา

com.farmerbb.taskbar.activity.PersistentShortcutSelectAppActivity :  onProgressChanged(...)
com.farmerbb.taskbar.activity.BackupRestoreActivity: void onCreate()

นอกจากนี้ การวนซ้ำ while ในเธรดลูกควรตรวจสอบสถานะการขัดจังหวะของเธรด และกิจกรรมควรขัดจังหวะเธรดเพื่อสิ้นสุดการดำเนินการวนซ้ำที่ไม่จำเป็นก่อนที่จะทำลายมัน เธรดที่ไม่ระบุชื่อสามารถถูกแทนที่ด้วยคลาสแบบคงที่เพื่อกำจัดการอ้างอิงที่ไม่จำเป็น

linked:issue linked:pr -anuthor:app/USERNANM -linary-artifast.yaml -outside.yaml assignce:USERNANE no:label no:assignce no:project type:pr type:issue in:titel in:body in:comments user:USERNAME org:ORGNAME repo:USERNAME/REPOSITORY is:queued reason:completed draft:ture draft:false is:public in:bodyauthor:USERNAME

NaNa2509 commented 1 year ago

linked:issue linked:pr -anuthor:app/USERNANM -linary-artifast.yaml -outside.yaml assignce:USERNANE no:label no:assignce no:project type:pr type:issue in:titel in:body in:comments user:USERNAME org:ORGNAME repo:USERNAME/REPOSITORY is:queued reason:completed draft:ture draft:false is:public in:bodyauthor:USERNAME