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

Originator:ckozinoglu
Number:rdar://33683103 Date Originated:August 2 2017, 3:54 PM
Status:Resolved Resolved:August 2 2017, 10:00 PM
Product:Developer Tools Product Version:XCode 8.3.3 / 9.x+
Classification:Bug Reproducible:Consistently
 
Resolved:
https://bugs.swift.org/browse/SR-5625

PR:
https://github.com/apple/swift/pull/11341

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

Comments

Resolved

https://github.com/apple/swift/pull/11341

By ckozinoglu at Aug. 4, 2017, 4:25 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!