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:
- 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:
- 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.
According to our research, there are misuses about the following AsyncTask class:
( in com.tananaev.logcat. MainActivity)
The problems is:
I think we can make following changes to fix the misuse problems:
private final MainActivity _contextas example, it can be changed toprivate final WeakReference<MainActivity> _context.