cpp_client_telemetry
cpp_client_telemetry copied to clipboard
Fix memory Leaks on iOS
Observing significant leaks on iOS devices when using 1-DS to send telemetry. Making NSURLSession static instead of creating a new instance for every telemetry event resolved the issue of memory leakage. Attaching snapshots from instruments where memory usage is being tracked with a static NSURLSession and a non static one.
pasting here from the 1ds-sdk team's channel -
Hi team.
We are observing significant memory spiking and leaks with 1-DS on iOS devices. I'm attaching a snapshot from the leaks profile taken from instruments. I have tested with the fixes made in this Pull Request. As we can see in the snapshot the memory is spiking quite fast and leaking a significant amount as well.
On further analysis we have found out that for every 1-DS telemetry event we send, we are creating a new URL session. Instead of which if a static URL session is used, the leaks and spiking aren't observed anymore. Attaching a screenshot of the same.
Wanted to know if there is any reason behind having unique URL sessions for each telemetry request and if making the URL session static might cause any issues. Here is a link to the draft PR.
Adding @eduardo-camacho as reviewer, as he has written this part of iOS code.
Hey @eduardo-camacho @lalitb can you please re review this PR
Effectively this change is more disruptive than previous version when Lalit commented about the global static, and the global static thing is still present; am I missing something here? If we are going to allow the global statics in this case, then it's just cleaner how it was before splitting files. Would you agree @lalitb?
Yes, I too feel so, the initial approach was much cleaner if we can't get rid of global statics with this approach. Sorry @samirnen if there are too many iterations :)