Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misuse about AsyncTask #214

Open
pangeneral opened this issue Aug 13, 2019 · 1 comment
Open

Misuse about AsyncTask #214

pangeneral opened this issue Aug 13, 2019 · 1 comment

Comments

@pangeneral
Copy link

pangeneral commented Aug 13, 2019

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

  1. fr.unix_experience.owncloud_sms.engine.ASyncSMSRecovery.SMSRecoveryTask
  2. fr.unix_experience.owncloud_sms.engine.ASyncContactLoad.ContactLoadTask

The problems are:

  1. 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
  2. Their instances 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 final RestoreMessagesActivity _context as example, it can be changed tp private final WeakReference<RestoreMessagesActivity> _context.
  2. Add a AsyncTask field in the corresponding Activities which use AsyncTask. These field refer to the annoymous AsyncTask object such as new ASyncSMSRecovery.SMSRecoveryTask(me, _account).execute(). Then invoke cancel() in the onDestroy() method of Activities.

These are my suggestions above, thank you.

@nerzhul
Copy link
Owner

nerzhul commented Sep 23, 2019

Hello, feel free to propose a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants