Uploaded image for project: 'Swift'
  1. Swift
  2. SR-919

Memory Leak using "try?"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Environment:

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

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              I5s Khunakorn Jandee
              Reporter:
              AnthonyMDev Anthony Miller
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: