Skip to content

Conversation

dumganhar
Copy link

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.

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 '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
Copy link
Author

I don't know why travis build was failed. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants