tracker-control-android icon indicating copy to clipboard operation
tracker-control-android copied to clipboard

Activity memory leak caused by anonymous threads

Open cuixiaoyiyi opened this issue 3 years ago • 1 comments

Possible Memory Leak

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. Please check the links below.

Occurrences

https://github.com/TrackerControl/tracker-control-android/blob/master/app/src/main/java/net/kollnig/missioncontrol/details/ActionsFragment.java#L146 https://github.com/TrackerControl/tracker-control-android/blob/master/app/src/main/java/eu/faircode/netguard/ActivityMain.java#L427

Possible Solution

If it is necessary, it can be changed to static class + weak reference to eliminate the reference to the activity, which may cause memory leaks. Further discussion is welcome.

cuixiaoyiyi avatar Aug 31 '22 08:08 cuixiaoyiyi

Thanks for flagging this! The threads should finish though at some point and free memory again, no? If you have time, I'd appreciate a PR.

kasnder avatar Aug 31 '22 10:08 kasnder