Skip to content

memory leak about AsyncTask #15

@cuixiaoyiyi

Description

@cuixiaoyiyi

According to our research, there are misuses about the following AsyncTask class:
( in com.tananaev.logcat. MainActivity)

private ReaderTask readerTask;
//……
private class ReaderTask extends AsyncTask<Void, StatusUpdate, Void> 

The problems is:

  1. It is inner class. It holds strong reference to the GUI element of Activity( MainActivity ), which can lead to memory leak when the Activity is destroyed and the AsyncTask did not finish.

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 final MainActivity _context as example, it can be changed to private final WeakReference<MainActivity> _context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions