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-5395] Memory management issue in nonescaping block with unowned self in ObjC subclasses #47969

Closed
swift-ci opened this issue Jul 7, 2017 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 7, 2017

Previous ID SR-5395
Radar None
Original Reporter tomquist (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 4.0 (swiftlang-900.0.45.6 clang-900.0.26)
Target: x86_64-apple-macosx10.9

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

md5: 8a506766f8df6e0b35b19a5ee68add55

duplicates:

  • SR-5310 unowned object crashes in noescape closures

Issue Description:

When compiling a project with Swift 3.2 we found a memory issue due to an (unnecessary) "unowned" keyword in a non-escaping block. I was able to create a minimal example which crashes with an EXC_BAD_ACCESS signal, both when compiled with Swift 3.2 and 4.0:

import Foundation

class A: NSObject {
    
    let b = B()
    
    func doSomething() {
        b.list.forEach { [unowned self] _ in
            print(self.b.list)
        }
    }
    
}

class B {
    let list = [1, 2]
}
A().doSomething()

The crash disappears, when A doesn't inherit from NSObject. I'm not 100% sure if this is a compiler issue or a programmer error but in my understanding adding [unowned self] shouldn't change anything in a non-escaping block.

When compiling the same code with Swift 3.1, it doesn't crash, so this is at least a compatibility issue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant