Object created through protocol not released if protocol tagged with @objc
| Originator: | Antonio.Cabezuelo | ||
| Number: | rdar://34993758 | Date Originated: | |
| Status: | Resolved: | ||
| Product: | Swift | Product Version: | |
| Classification: | Bug | Reproducible: | Always |
Summary:
Given a protocol and a class that implements this protocol. Creating an object casting the class to the protocol and invoking init on the protocol, creates an object that is never released if the protocol is tagged with @objc
Steps to Reproduce:
Executing the following code:
@objc
protocol P: class, NSObjectProtocol {
init(name: String)
var name: String { get }
}
class A: NSObject, P {
required init(name: String) {
self.name = name
super.init()
}
deinit {
print("A deinit")
}
let name: String
}
let c: AnyClass = A.self
if let proto = c as? P.Type {
print("Proto")
_ = proto.init(name: "Hi")
}
Expected Results:
Console show:
Proto
A deinit
Actual Results:
Console show:
Proto
Version/Build:
iOS 11.0
Notes:
If the protocol is not tagged with @objc the console shows the expected results.
Comments
No Comments
Comments
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!