This repository was archived by the owner on Jun 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 344
This repository was archived by the owner on Jun 1, 2024. It is now read-only.
Misuse of AsyncTask #3051
Copy link
Copy link
Open
Labels
BugThis is an issue with Slide. This is where something in the app isn't working as intended.This is an issue with Slide. This is where something in the app isn't working as intended.Good First IssueThis issue is perfect for you if you are new to Slide.This issue is perfect for you if you are new to Slide.Has SolutionThere is a solution to this issue posted in the comment.There is a solution to this issue posted in the comment.
Description
According to our research, there are misuses about the following classes:
me.ccrama.redditslide.Voteme.ccrama.redditslide.Activities.CommentsScreenSingle.AsyncGetSubredditNameme.ccrama.redditslide.Activities.Inboxme.ccrama.redditslide.Activities.LiveThread
The problems are:
- There are many annoymous inner AsyncTask classes in
LiveThreadandInbox. They hold strong reference to the GUI element of Activity, which can lead to memory leak when the Activity is destroyed and the AsyncTask did not finish. Similar problem also exists inVoteandAsyncGetSubredditName. - The instances of these AsyncTask classes are not cancelled before the Activity is destroyed, which can lead to the wrong invocation of onPostExecute
I think we can make following changes to fix the misuse problems:
- I think the GUI-related fields should be wrapped into WeakReference. Take
private View vinVoteas example, it can be changed tpprivate WeakReference<view> v. Besides, use non-anonymous inner static classes to replace these annoymous classes. - Add a AsyncTask field in the corresponding Activities which use AsyncTask. These field refer to the annoymous AsyncTask object. Then invoke
cancel()in the onDestroy() method of Activities.
These are my suggestions above, thank you.
Metadata
Metadata
Assignees
Labels
BugThis is an issue with Slide. This is where something in the app isn't working as intended.This is an issue with Slide. This is where something in the app isn't working as intended.Good First IssueThis issue is perfect for you if you are new to Slide.This issue is perfect for you if you are new to Slide.Has SolutionThere is a solution to this issue posted in the comment.There is a solution to this issue posted in the comment.