-
-
Notifications
You must be signed in to change notification settings - Fork 45
Crash solved while moving back and forth in connect message screen #3436
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
Conversation
📝 WalkthroughWalkthroughA single null assignment statement was removed from the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Jignesh-dimagi can you add more context here around the crash itself (stacktrace or firebase link) and how is this an apt solution for that crash. |
Sure, I just updated the description for the same. |
| @Override | ||
| public void onDestroyView() { | ||
| super.onDestroyView(); | ||
| binding = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a common pattern we follow across fragments and I don't see a point of code updating the UI after the fragment has been destroyed. As such maybe the better solution here is one similar to what we did here by introducing a non-null check on view binding. -
MessageManager.retrieveMessages(requireActivity(), success -> {
if(binding!=null) refreshUi();
});
An alternative can be to cancel the callback itself on onDestroy to fix the root of the issue itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an avenue worth exploring 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes correct to check for null but what if already execution inside refreshUi method and binding becomes null? Making binding null, we are not achieving anything but extra checks only. Your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually curious why we were setting the binding to null here in the first place too, especially if this is a common pattern in the codebase. Was this to prevent a memory leak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually curious why we were setting the binding to null here in the first place too, especially if this is a common pattern in the codebase. Was this to prevent a memory leak?
Yes, my sense is it's to do proper garbage collection as binding keep references to all fragment views and hence keeping it alive can mean stopping views from getting garbage collected which can be memory intensive.
Yes correct to check for null but what if already execution inside refreshUi method and binding becomes null
yeah that's a good point. I think callback cancellation should be the way to go here in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my sense is it's to do proper garbage collection as binding keep references to all fragment views and hence keeping it alive can mean stopping views from getting garbage collected which can be memory intensive.
Its good to make it null but actually view get destroyed first and than fragment so should not be a problem for garbage collection.
yeah that's a good point. I think callback cancellation should be the way to go here in that case.
Yeah its already planned here. This is bit of work to be done.
I think current solution should be good enough till we implement above ticket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually view get destroyed first and than fragment so should not be a problem for garbage collection.
Ahh excellent observation! Think I am good with this fix in that case as long as we apply it uniformly across all fragments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, done at all places
Technical Summary
https://dimagi.atlassian.net/browse/QA-8252
This crash was happening if user is navigating too fast between connect message and channel list screen.
Firebase log
There was a condition where binding getting null due to destroyed view and app's main thread was here updating the UI. This crash will not happen if network gets completed, updated UI and than fragment is destroyed.
QA Plan
QA should navigate between connect message and channel list screen and app should not crash
Labels and Review