Memory leak


In this example we try to implement a memory leak as we demonstrate in Python showing how Rust makes us avoid it. So far this code has compilation errors.


examples/other/memory-leak/src/main.rs
#![allow(unused_variables)]

#[allow(dead_code)]
struct Thing {
    data: String,
    other: Option<Box<Thing>>,
}

fn main() {
    alloc();
}

fn alloc() {
    let mut a = Thing {
        data: String::from("abc"),
        other: None,
    };

    let mut b = Thing {
        data: String::from("abc"),
        other: None,
    };

    a.other = Some(Box::new(b));
    b.other = Some(Box::new(a));
}