Skip to content

Commit c3f8858

Browse files
committed
[Concurrency] Test showing that runDetached leaks
1 parent 63d5cf1 commit c3f8858

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
// REQUIRES: concurrency
5+
6+
class X {
7+
init() {
8+
print("X: init")
9+
}
10+
deinit {
11+
print("X: deinit")
12+
}
13+
}
14+
15+
func test_detach() async {
16+
for _ in 1...3 {
17+
let x = X()
18+
let h = Task.runDetached {
19+
print("inside: \(x)")
20+
}
21+
await h.get()
22+
}
23+
// CHECK: X: init
24+
// CHECK: inside: main.X
25+
// CHECK: X: deinit
26+
}
27+
28+
29+
@main struct Main {
30+
static func main() async {
31+
await test_detach()
32+
}
33+
}

0 commit comments

Comments
 (0)