Skip to content

Instantly share code, notes, and snippets.

@avii-7
Last active February 5, 2026 17:04
Show Gist options
  • Select an option

  • Save avii-7/7e85fd35572f52e1122915ed62332499 to your computer and use it in GitHub Desktop.

Select an option

Save avii-7/7e85fd35572f52e1122915ed62332499 to your computer and use it in GitHub Desktop.
Deallocation Issue
import SwiftUI
final class StreamListner {
private let stream: AsyncStream<Int> = AsyncStream<Int> { (continuation) in
Task {
for i in 1...20 {
try? await Task.sleep(for: .seconds(2))
continuation.yield(i)
}
}
}
init() {
Task { [weak self] in
guard let self else { return }
for await value in self.stream {
self.notifyAPI(value)
}
}
}
private func notifyAPI(_ value: Int) { print("New Stream value: \(value)") }
deinit {
print("Deinit AsyncStreamTests")
}
}
struct AsyncStreamView: View {
var body: some View {
Text("Hello, World!")
.onAppear {
let _ = StreamListner()
}
}
}
#Preview {
AsyncStreamView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment