-
-
Notifications
You must be signed in to change notification settings - Fork 921
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
Activity memory leak caused by anonymous threads #393
Comments
Thanks. Not sure if this is an issue here. I want to keep the Activity while the thread/runner is working. I will try to have a closer look. Hints/tips are welcome. ;) |
Any more hints? If I'm not mistaken, the behavior is by design. The anonymous class should be able to control the outer class (Activity). If the inner class was successful it finishes the outer class as well. If the inner class was unsuccessful it just ends his self (and with that it reference to the outer class?!). I'm still not sure if this is an issue here. But I'm no Java programming professional, just a hobbyist. |
** The anonymous class should be able to control the outer class (Activity). ** If the activity has been released by the manager in Android platform, a (WindowManager.BadTokenException) may happen after the Toast.makeText invocation. |
|
Possible Memory Leak
An anonymous inner class will hold a reference to the this pointer of the outer class and will not be released until the thread ends.
It will hold the Activity and prevent its timely release. Please check the links below.
Occurrences
https://github.com/ikarus23/MifareClassicTool/blob/master/Mifare%20Classic%20Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/WriteTag.java#L1253
https://github.com/ikarus23/MifareClassicTool/blob/master/Mifare%20Classic%20Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java#L458
Possible Solution
If it is necessary, it can be changed to static class + weak reference to eliminate the reference to the activity, which may cause memory leaks.
Further discussion is welcome.
The text was updated successfully, but these errors were encountered: