Fixes #832 (Is there a way to 'clean up' socket connection to avoid memory leaks, before attempting to reconnect?)
Fixes #938 (Memory leak when use native engine)
Fixes #995 (if you socket resart many time,cpu is very busy and Forever and ever)
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.
The URLSession is retained because neither invalidateAndCancel() nor finishTasksAndInvalidate() has been called. Consequently, this leads to memory leaks after initializing a new WebSocket and establishing a connection.
Implementation Details 🚧
Invalidate the NativeEngine's URLSession at WebSocket dealloc.
Issue Link 🔗
Fixes #832 (Is there a way to 'clean up' socket connection to avoid memory leaks, before attempting to reconnect?) Fixes #938 (Memory leak when use native engine) Fixes #995 (if you socket resart many time,cpu is very busy and Forever and ever)
Goals âš½
According to the Apple document,
The URLSession is retained because neither invalidateAndCancel() nor finishTasksAndInvalidate() has been called. Consequently, this leads to memory leaks after initializing a new WebSocket and establishing a connection.
Implementation Details 🚧
Invalidate the NativeEngine's URLSession at WebSocket dealloc.
Unit Test Results: Passed