sadr0b0t / yashlang

PeerTube and YouTube player for Android with local playlists and whitelisted recommendations
GNU General Public License v3.0
52 stars 3 forks source link

Activity memory leak caused by anonymous threads #152

Open cuixiaoyiyi opened 2 years ago

cuixiaoyiyi commented 2 years ago

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/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/SearchOnlinePlaylistActivity.java#L131 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L1384 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L1919 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L1987 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L1405 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L2334 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L1953 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L683 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L699 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/WatchVideoActivity.java#L2021 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/AddPlaylistActivity.java#L674 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/AddPlaylistActivity.java#L454 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/ConfigureProfileActivity.java#L261 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/ConfigureProfileActivity.java#L237 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/PlaylistActivity.java#L368 https://github.com/sadr0b0t/yashlang/blob/master/app/src/main/java/su/sadrobot/yashlang/ConfigurePlaylistActivity.java#L135

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.