-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.non-optimized onlyFlag: An issue whose reproduction requires non-optimized compilationFlag: An issue whose reproduction requires non-optimized compilationruntimeThe Swift RuntimeThe Swift Runtimestandard libraryArea: Standard library umbrellaArea: Standard library umbrella
Description
Previous ID | SR-426 |
Radar | None |
Original Reporter | austin (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Environment
Building on OS X 10.11.2, revision 73872e5.
Additional Detail from JIRA
Votes | 0 |
Component/s | Standard Library |
Labels | Bug, NotOptimizedOnly, Runtime |
Assignee | jder (JIRA) |
Priority | Medium |
md5: 66dcf74255f01d0bc1c3c7eded17fdfe
blocks:
- SR-88 Remove old mirrors
Issue Description:
The following code appears to produce a memory leak. When it is run, the relevant class's `deinit` is never called:
class BasicClass {
let a : Int
init(_ a: Int) {
print("BasicClass being init'ed with value \(a)")
self.a = a
}
deinit {
print("BasicClass being deinit'ed with value \(a)")
}
}
enum Bar<T> {
case First(T)
}
enum Baz<T, U> {
case First(T), Second(U), Third, Fourth
}
func doSomething() {
let myThing : Any = Bar.First(BasicClass(10))
// bad behavior also happens with multi-payload generic enums
// bad behavior also happens with a tuple, like "(1, 2, BasicClass(10))"
// bad behavior does not happen with just a bare "BasicClass(10)"
// A:
if let foo = myThing as? Any.Type {
print("myThing is a metatype")
}
}
doSomething()
In particular, the thing that causes trouble is the conditional downcast to Any.Type (marked by the comment 'A'). If the if-let statement is removed, the init and deinit run properly. If the if-let statement is present, only the init runs properly.
A downcast to a non-metatype seems to work fine. I have not tried downcasting to other metatypes.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.non-optimized onlyFlag: An issue whose reproduction requires non-optimized compilationFlag: An issue whose reproduction requires non-optimized compilationruntimeThe Swift RuntimeThe Swift Runtimestandard libraryArea: Standard library umbrellaArea: Standard library umbrella