You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there. We noticed recently that the steps you suggest to track network requests automatically with RUM cause memory leaks due to an important detail that Apple notes in their docs when using the URLSession.init(configuration:delegate:delegateQueue:) initializer.
Your instructions suggest implementing automatic network network request tracking like so:
In our implementation we have any empty delegate like this:
public final class OurURLSessionDelegate: NSObject, URLSessionDataDelegate {}
The Apple docs for the URLSession.init(configuration:delegate:delegateQueue:) initializer have this warning for the delegate parameter:
Important
The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you do not invalidate the session by calling the invalidateAndCancel() or finishTasksAndInvalidate() method, your app leaks memory until it exits.
This means that if you don't call invalidateAndCancel() or finishtasksandinvalidate() on URLSession's after use you'll end up with memory leaks.
Example of some leaked URLSessionDelegates:
I would suggest that you at least mention this detail in your docs and possibly look at other ways of implementing automatic network request tracking.
Reproduction steps
Create some URLSession's with the suggested implementation and have a look at Xcode's Memory Debugger or Instruments afterwards.
SDK logs
No response
Expected behavior
No response
Affected SDK versions
We're on 2.22.1 but any version with this setup would be affected
Latest working SDK version
The one before this tracking was added I guess?
Did you confirm if the latest SDK version fixes the bug?
No
Integration Methods
SPM
Xcode Version
No response
Swift Version
No response
MacOS Version
No response
Deployment Target
No response
Device Information
No response
Other relevant information
No response
The text was updated successfully, but these errors were encountered:
Thanks for the report 👍 Our instrumentation does not generate a leak directly, URLSession does, so I will remove the bug tag. Tho I agree that since our instrumentation relies on session's delegate, we should mention this in doc. I will make an update.
Describe the bug
Hi there. We noticed recently that the steps you suggest to track network requests automatically with RUM cause memory leaks due to an important detail that Apple notes in their docs when using the
URLSession.init(configuration:delegate:delegateQueue:)
initializer.Your instructions suggest implementing automatic network network request tracking like so:
In our implementation we have any empty delegate like this:
The Apple docs for the
URLSession.init(configuration:delegate:delegateQueue:)
initializer have this warning for thedelegate
parameter:This means that if you don't call
invalidateAndCancel()
orfinishtasksandinvalidate()
onURLSession
's after use you'll end up with memory leaks.Example of some leaked URLSessionDelegates:
I would suggest that you at least mention this detail in your docs and possibly look at other ways of implementing automatic network request tracking.
Reproduction steps
Create some
URLSession
's with the suggested implementation and have a look at Xcode's Memory Debugger or Instruments afterwards.SDK logs
No response
Expected behavior
No response
Affected SDK versions
We're on 2.22.1 but any version with this setup would be affected
Latest working SDK version
The one before this tracking was added I guess?
Did you confirm if the latest SDK version fixes the bug?
No
Integration Methods
SPM
Xcode Version
No response
Swift Version
No response
MacOS Version
No response
Deployment Target
No response
Device Information
No response
Other relevant information
No response
The text was updated successfully, but these errors were encountered: