8000 [SR-4893] [weak self] leaks · Issue #47470 · swiftlang/swift · GitHub 8000
[go: up one dir, main page]

Skip to content
[SR-4893] [weak self] leaks #47470
@swift-ci

Description

@swift-ci
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0