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-919] Memory Leak using "try?" #43531

Closed
swift-ci opened this issue Mar 11, 2016 · 9 comments
Closed

[SR-919] Memory Leak using "try?" #43531

swift-ci opened this issue Mar 11, 2016 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself non-optimized only Flag: An issue whose reproduction requires non-optimized compilation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-919
Radar None
Original Reporter AnthonyMDev (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Compiler: Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Target: x86_64-apple-darwin15.3.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, NotOptimizedOnly
Assignee I5s (JIRA)
Priority Medium

md5: df0612473392fcffe109bd7256c7f2a4

is duplicated by:

  • SR-972 Memory leak when using try?

Issue Description:

I'm seeing a memory leak of a `_SwiftNativeNSError` whenever I'm using "try?". The error I'm throwing is not an `NSError`, it is a swift enum conforming to `ErrorType`.

Here is some example code.

enum Error: ErrorType {
    case A, B
}

 private class func setUpFooBar() {
    if let foo = self.bar {
      self.fooBar = try? value(foo)
    }
  }

private func value(foo) throws -> AnyObject {
    throw Error.A
}

Changing the code to use "try" with a "catch" block gets rid of the leaks in Instruments.

@gottesmm
Copy link
Member

Does this happen with optimization?

@belkadan
Copy link
Contributor

Which version of the Swift compiler are you using? (swiftc -v)

@swift-ci
Copy link
Collaborator Author

Comment by Anthony Miller (JIRA)

@gottesmm: I'll check that out now. Will update soon.
@belkadan: I've added the compiler version to the environment section.

@swift-ci
Copy link
Collaborator Author

Comment by Anthony Miller (JIRA)

@gottesmm: This does seem to still be occurring with or without optimization

@gottesmm
Copy link
Member

Anthony Miller: Can you put a colon next time when you ask people specific questions.

I thought since there was no colon at first that I wrote your comment.

Ok. Since it occurs in either case, it could be a frontend bug.

@swift-ci
Copy link
Collaborator Author

Comment by Anthony Miller (JIRA)

Sorry about that, I've fixed that and added colons.

Hope that your team is able to reproduce and solve this issue. Thanks, Anthony.

@belkadan
Copy link
Contributor

@slavapestov fixed this in ebb8d73.

@swift-ci
Copy link
Collaborator Author

Comment by Anthony Miller (JIRA)

That's great news. Is this fix included in Swift 2.2?

@belkadan
Copy link
Contributor

Unfortunately not, but we're considering it if there's a 2.2.1. Meanwhile your workaround is what you already mentioned: use an explicit do/catch. (And you can write a wrapper function that's nearly equivalent.)

@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 non-optimized only Flag: An issue whose reproduction requires non-optimized compilation
Projects
None yet
Development

No branches or pull requests

3 participants