rensbreur / SwiftTUI

SwiftUI for terminal applications
MIT License
1.23k stars 47 forks source link

Node has a strong reference to parent node will cause retain cycle problem #33

Closed piuSora closed 5 months ago

piuSora commented 6 months ago

reproduction example:

import SwiftTUI

struct DeinitView: View {
    var body: some View {
        Text("hello, world")
    }
}

struct ContentView: View {
    @State var show: Bool = true
    var body: some View {
        VStack(alignment: .center, spacing: 3) {
            Text("ANSI Colors")
                .bold()
                .padding(.horizontal, 1)
                .border(style: .double)
            if show {
                DeinitView()
            }
            Button("click") {
                //deinitView's node should be release after click
                show = false
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
    }
}
piuSora commented 6 months ago

I simply tried mark parent to weak can fix this issue.