Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Misuse of AsyncTask #3051

Open
Open
@pangeneral

Description

@pangeneral

According to our research, there are misuses about the following classes:

  1. me.ccrama.redditslide.Vote
  2. me.ccrama.redditslide.Activities.CommentsScreenSingle.AsyncGetSubredditName
  3. me.ccrama.redditslide.Activities.Inbox
  4. me.ccrama.redditslide.Activities.LiveThread

The problems are:

  1. There are many annoymous inner AsyncTask classes in LiveThread and Inbox. 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 in Vote and AsyncGetSubredditName.
  2. 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:

  1. I think the GUI-related fields should be wrapped into WeakReference. Take private View v in Vote as example, it can be changed tp private WeakReference<view> v. Besides, use non-anonymous inner static classes to replace these annoymous classes.
  2. 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

No one assigned

    Labels

    BugThis 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.Has SolutionThere is a solution to this issue posted in the comment.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions