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

Memory leak when using `try?`

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Labels:

      Description

      We've discovered an interesting memory leak when using `try?`. Here's an example to reproduce it:

      struct Error: ErrorType {}
      
      func something() throws {
          throw Error()
      }
      
      for _ in 0..<10000000 {
          // Leaks if you use `try?`
          _ = try? something()
      
          // Doesn't leak if you handle the error
          // do {
          //     try something()
          // } catch {}
      }
      

      To see this in action you can compile this with `swiftc` and then execute it through instruments using the leaks tool. We're seeing this in both Swift 2.1 and the most recent 2.2 beta bundled with the Xcode 7.3 beta.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              keith Keith Smiley
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: