Skip to content

Commit a6974da

Browse files
committed
prove that autoreleasepool works in a task
1 parent 54ce3ed commit a6974da

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bk1ch12p490autoreleasepool/bk1ch12p490autoreleasepool/ViewController.swift

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import UIKit
33

44
class ViewController: UIViewController {
55

6-
let which = 2
6+
let which = 3
77

88
override func viewDidAppear(_ animated: Bool) {
99
super.viewDidAppear(animated)
1010

1111
switch which {
1212
case 1: self.test()
1313
case 2: self.test2()
14+
case 3:
15+
Task {
16+
await self.test3()
17+
}
1418
default: break
1519
}
1620
}
@@ -36,6 +40,18 @@ class ViewController: UIViewController {
3640
}
3741
}
3842
}
43+
44+
// works fine in an async function
45+
func test3() async {
46+
let path = Bundle.main.path(forResource: "001", ofType: "png")!
47+
for j in 0 ..< 50 {
48+
autoreleasepool {
49+
for i in 0 ..< 100 {
50+
let im = UIImage(contentsOfFile: path)
51+
}
52+
}
53+
}
54+
}
3955

4056
func dummy () {
4157
let myMutableArray = NSMutableArray()

0 commit comments

Comments
 (0)