You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have an Any? containing a CFError, and you cast that to an Error, your CFError object will leak. If you cast using as? NSError instead of as? Error, the leak does not occur.
Code:
importFoundationfuncleak() {
letsomething: Any? = CFErrorCreate(kCFAllocatorDefault, "Foo"asCFString, 1, nil)
ifleterror = somethingas? Error {
print("Error: \(error.localizedDescription)")
}
}
leak()
print("Now run leaks on the process. You will find that the CFError has leaked.")
CFRunLoopRun()
Retain-release history of the CFError according to Instruments:
Lines 2 through 4 appear to contain the key. Examining the traces for each in Instruments reveals that each of these lines occurs within _getErrorEmbeddedNSErrorIndirect. In line 2, initializeWithCopy retains the error; in line 3, protocol witness for Error._getEmbeddedNSError() retains it again, and then in line 3, it's released by _getErrorEmbeddedNSErrorIndirect. The second retain, however, is never balanced.
I've included a sample project to demonstrate the problem. Run it, then run the leaks command (or examine it in Instruments) to see the leak. Change "as? Error" to "as? NSError" to see the leak go away.
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Xcode 9.3
Xcode 9.4 beta 2
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Apple Swift version 4.1.1 (swiftlang-902.0.53 clang-902.0.39.2)
Swift version 4.2-dev (LLVM 072be1cf17, Clang c7422ffe24, Swift 3843d39297)
Additional Detail from JIRA
md5: b68a4ce9dd61b2117ff719fbbeb397a6
Issue Description:
If you have an Any? containing a CFError, and you cast that to an Error, your CFError object will leak. If you cast using as? NSError instead of as? Error, the leak does not occur.
Code:
Retain-release history of the CFError according to Instruments:
Lines 2 through 4 appear to contain the key. Examining the traces for each in Instruments reveals that each of these lines occurs within _getErrorEmbeddedNSErrorIndirect. In line 2, initializeWithCopy retains the error; in line 3, protocol witness for Error._getEmbeddedNSError() retains it again, and then in line 3, it's released by _getErrorEmbeddedNSErrorIndirect. The second retain, however, is never balanced.
I've included a sample project to demonstrate the problem. Run it, then run the leaks command (or examine it in Instruments) to see the leak. Change "as? Error" to "as? NSError" to see the leak go away.
The text was updated successfully, but these errors were encountered: