But if you do allocate URLSessions dynamically, remember to clean up afterwards. Either finish tasks and invalidate or invalidate and cancel. But if you don't clean up, you'll leak memory.
Detail
In the project I'm working on, we got this weird error:
Error Domain=NSPOSIXErrorDomain
Code=28
“No space left on device”
UserInfo={_kCFStreamErrorCodeKey=28, _kCFStreamErrorDomainKey=1}
Googling that lead us to discover that "space" here is probably not referring to RAM or disk space, but that as of iOS 14 this error shows up when you have too many URLSessions going at once:
Summary
According to Apple, we should avoid creating instances of
URLSession
:Detail
In the project I'm working on, we got this weird error:
Googling that lead us to discover that "space" here is probably not referring to RAM or disk space, but that as of iOS 14 this error shows up when you have too many URLSessions going at once:
Test plan
MockUrlSession
that were created but not calledfinishTasksAndInvalidate()
before it's destroyed.MockUrlSession
are invalidated on everytearDown
that usesMockUrlSession
Issues