rensbreur / SwiftTUI

SwiftUI for terminal applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

piuSora opened this issue · comments

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)
    }
}

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