Closed Yannshu closed 3 years ago
hi @Yannshu ! Thanks for this other PR 🙏 appreciate the contribution.
I've tested both fixes and they work fine , the leaks have disappeared. I'm putting everything together in another branch with both fixes.
I'll update you once it's ready!
That's good to hear, thanks for having a look into this @diegoserranoa. Looking forward to the coming release with these fixes!
Hi @Yannshu , I've created a new PR merging the two solutions and also added a fix for another leak I was able to find. Can you please test and let me know if it's working correctly for you? 🙏
Thanks!
Thanks @diegoserranoa. Let's continue the discussion there 😄
Released version 2.18.1 with this fix. Thanks for the help!
Closing this PR.
Hello again 👋
Had a bit of time this afternoon, so I investigated and solved the leak reported by @astamato in issue https://github.com/Wootric/WootricSDK-Android/issues/97. This leak is can be easily spotted by Leak Canary and reproduced by displaying the survey in one activity, closing the survey, then finishing this activity and opening another one. You can view the heap analysis result in the following gist: link.
This PR fixes 2 different leaks related to holding hard references to activity objects. It will be easier to review it commit per commit.
Changes:
SurveyManager
. Looking at the code structure, this isn't needed. This was causing a memory leak when navigating to another activity, as the hard references were preventing the previous activity to be garbage collected.FragmentManager.currentEvent
attribute tonull
when the survey is finished (or doesn't load). TheCurrentEvent
class holds hard references to activity objects, and as for 1., when navigating to another activity, these references were preventing the previous activity to be garbage collected.How to test it:
To observe the memory leak:
git am -3 -k spot-leak-setup.patch
.To test this PR
Same thing than for my other PR. I'm obviously not the most familiar person with this codebase, I just spent a bit of time fixing these memory leaks. While all the unit tests still pass, I would advise to fully test the different behaviours of the survey before publishing a new version with this change, to make sure it did not create any regression.