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

[SR-4893] [weak self] leaks #47470

Closed
swift-ci opened this issue May 15, 2017 · 2 comments
Closed

[SR-4893] [weak self] leaks #47470

swift-ci opened this issue May 15, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4893
Radar None
Original Reporter jholliday (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: b58edaf47ba3c477f8bf84f483270539

duplicates:

  • SR-3805 Creating a strong reference to self in a closure should warn if self is never accessed "strongly"

Issue Description:

When declaring a closure, it's unclear to me what scope the strong reference to self is pulled from. When hunting for a leak, I discovered that my [weak self] declaration at the beginning of a closure caused a strong reference from the encompassing scope, which caused a leak.

I asked Joe about this on Twitter, and he said

"To me, that seems like a language bug. We should capture self weakly transitively through the outer closure."
For more context: https://twitter.com/jckarter/status/864165194783535104

I'm attaching a sample project that I can reproduce the leak with. Hitting the bar button item in the upper right will push a view controller on the stack that never gets cleaned up because it has a retain cycle.

@swift-ci
Copy link
Collaborator Author

Comment by Jeff Holliday (JIRA)

Just to clarify a bit - when I looked at this, I figured it's because self gets captured in the context that is declaring the closure. I found this to be confusing (but not bugged) because it meant that the declaration of weak self, which is written within the curly braces of the closure, retains it outside that scope.

@belkadan
Copy link
Contributor

Thanks for the test case!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

2 participants