SocketRocket
SocketRocket copied to clipboard
Memory leak fix and cancel connection timeout timer in scheduleCleanup.
This Pull Request fixes two issues:
-
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 inSRWebSocket:dealloc
, it will never go there. This bug was found by analyzingAllocation List
in theInstruments
tool of Xcode. -
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. Sincedispatch_after
could not be cancelled, useperformSelector:withObject:afterDelay
&cancelPreviousPerformRequestsWithTarget:selector:object
instead.