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
Potential Memory Leak #5
Comments
Thank you for your help. Yes, I'm still struggling to find a good practice to avoid memory Leak. You can suggest any improvements for the project ^^ |
Here we need to tell the Validator that a new Activity is running things now. We can do this by overriding onActivityCreated in our fragment, it is called when an activity is created (even if setRetainInstance is set to true). In onActivityCreated we should update any validator with the new Context, this will remove the reference to our old Context and allow it to be garbage collected. The current AbstractValidator doesn't allow us to update the Context. A work around for this would be to instantiate a new Validator each time a new Activity is created. I think it would be nicer to be able to provide a new Context to the AbstractValidator |
Thanks for all @2bard |
Great library for easy form validation in Android, but I have a concern about potential memory leak in AbstractValidator class.
I found out that this Context reference, if instantiated inside a Fragment that setRetainInstance == true, well retain a reference to the first activity passed in constructor.
AFAIK, according to Android Activity lifecycle, when there's configuration change, e.g when user change display orientation, an Activity will be destroyed and recreated. But a setRetainInstance == true fragment, will not be recreated on a configuration change.
So, in the end of Activity recreation, my retained fragment still hold a reference to the previously 'destroyed' Activity context, which is certainly a memory leak. CMIIW
I would like to contribute in this library, planning to have a pull request of my suggested implementation within this week :)
The text was updated successfully, but these errors were encountered: