Rust 메모리 Dropping

mohadang·2023년 2월 19일
0

Rust

목록 보기
22/30
post-thumbnail

struct가 drop 될 때는, struct 자신이 제일 먼저 drop 되고, 이후에 그 자식들이 각각 drop 되고, 등의 순서로 처리

struct Bar {
    x: i32,
}

struct Foo {
    bar: Bar,
}

fn main() {
    let foo = Foo { bar: Bar { x: 42 } };
    println!("{}", foo.bar.x);
    // foo가 먼저 drop 되고
    // 그 다음에 foo.bar가 drop 됩니다
}
profile
mohadang

0개의 댓글