nextcloud / notes-android

✎ Android client for Nextcloud Notes app.
https://play.google.com/store/apps/details?id=it.niedermann.owncloud.notes
GNU General Public License v3.0
921 stars 134 forks source link

Activity memory leak caused by anonymous threads #1574

Closed cuixiaoyiyi closed 1 year 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/stefan-niedermann/nextcloud-notes/blob/master/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java#L141

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.

stefan-niedermann commented 1 year ago

Fixed by using an Executor.