Closed choulepoka closed 1 year ago
@benjamin-tang-pusher Any news on this pull-request? This a quite serious bug.
Hi, thanks for this, I will test it and get it merged.
Hi @fbenevides, I've tested this and its good to go. Could you release this as 0.5.3 ? pusher-websocket-swift will pin this to the latest version.
Problem: The dispatch work item created create a strong reference to
self
, which in turn have astrong
reference ondisconnectionWorkItem
, creating an infinite retain cycle that makes the NWWebSocket an immortal objectThis is a major memory leak for apps that try arbitrarily disconnect from the websocket (i.e.: a logout) and then reconnect later (i.e.: a login)
This cause multiple socket to be alive, and taking up a sizeable amount of system resources
Bug was introduced by commit 45eafe24fb1c9be1ab09f9c7fa97c30ba7aab09c
Solution Add the
[weak self] in
clause in the dispatch work item declaration, and add aguard let self else { return }
for the case whereself
is truly deallocated.The solution has been tested, and resolved the memory leak with no adverse side-effect