Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak fix and cancel connection timeout timer in scheduleCleanup. #525

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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