且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NSURLSession HTTP / 2内存泄漏

更新时间:2022-06-27 00:09:21

来自apple doc:

From apple doc:


会话对象保持强势在您的应用退出或明确使会话无效之前引用该代理。如果你没有使会话无效,你的应用程序会泄漏内存直到它退出。

The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you don’t invalidate the session, your app leaks memory until it exits.

同时查看你的项目 https://github.com/upyun/swift-sdk/tree/testleak 你需要打电话在sessionTask.resume()之后的finishTasksAndInvalidate(),因为您正在为每个请求创建会话

Also looking at your project https://github.com/upyun/swift-sdk/tree/testleak you need to call finishTasksAndInvalidate() after sessionTask.resume() since you are creating session per request