SocketRocket icon indicating copy to clipboard operation
SocketRocket copied to clipboard

Memory leak fix and cancel connection timeout timer in scheduleCleanup.

Open dumganhar opened this issue 6 years ago • 1 comments

This Pull Request fixes two issues:

  1. Uses weak SRWebSocket object in the block of _readUntilHeaderCompleteWithCallback. Since consumers has a _completion block which will retain SRWebSocket instance, if we uses strong self, cycle reference will occur. To Reproduce this issue, just simply connect an invalid website, e.g. ws:://echo111.websocket111.org111 , set a breakpoint in SRWebSocket:dealloc, it will never go there. This bug was found by analyzing Allocation List in the Instruments tool of Xcode.

  2. Should cancel connection timeout timer in scheduleCleanup method, otherwise, the SRWebSocket:dealloc method will be invoked only after the time (default: 60s) have come, which may cause memory increase. Since dispatch_after could not be cancelled, use performSelector:withObject:afterDelay & cancelPreviousPerformRequestsWithTarget:selector:object instead.

dumganhar avatar Jul 20 '17 03:07 dumganhar