optimizely / swift-sdk

Swift SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
https://www.optimizely.com/products/full-stack/
Apache License 2.0
21 stars 30 forks source link

Fix invalidate url sessions #446

Closed andredsp closed 2 years ago

andredsp commented 2 years ago

Summary

According to Apple, we should avoid creating instances of URLSession:

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:

Test plan

Issues

jaeopt commented 2 years ago

@andredsp Thanks for your contribution. We'll take a look at it.