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

Optional Enum (annotated with @objc) + Mutable Array Leak (Swift 3)

    XMLWordPrintable

    Details

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

      Description

      Summary:
      When a Swift class contains an optional Enum property that is marked with @objc, and this same class also contains a mutable (var) array holding at least one element, there is an unexpected memory leak.

      Steps to Reproduce:
      Steps:
      1) Download the attachment project (EnumMemoryLeak.zip) OR clone if from: https://github.com/Giphy/ios-memory-leak-sample
      2) Open the project in XCode
      3) Command + I
      4) Select Leaks Instrument
      5) Record

      You should now encounter leaks.

      Expected Results:
      No leaks.

      Observed Results:
      Memory leaking.

      Version:
      XCode:

      • Version 9.0 beta 4 (9M189t)
        (Same issue on 8.3.3 as well)

      Deployment Target:

      • 8.0+

      MacOS:

      • Version 10.12.5 (16F73)

      Notes:
      Work around:

      If we convert the optional enum class property to a non-optional, leak will disappear.

      // Let's convert the optional property to a non-optional
      var leakOptionalEnum: leakingObjCMarkedEnum = .memoryLeakCase

        Attachments

          Activity

            People

            Assignee:
            slavapestov Slava Pestov
            Reporter:
            cem Cem Kozinoglu
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: