4 ms·
You couldn't meaningfully "prevent memory leaks", and that's what Rust's Leakpocalypse was about. Suppose I have decided to model marriage. My Person type has
by tialaramex 3y ago
You couldn't meaningfully "prevent memory leaks", and that's what Rust's Leakpocalypse was about.
Suppose I have decided to model marriage. My Person type has a spouse: Option<Rc<Person>> and when you marry() another Person it fills out both spouse references. Now I make Bob and Alice, and marry them off, so Alice contains a reference to Bob, while Bob has a reference to Alice. Romantic. Next, I throw away my only Alice reference, but that's OK, I have a Bob, and Bob has a spouse field with a reference to Alice, so Alice isn't destroyed. Then I throw away Bob, likewise Alice has a reference to Bob, so Bob isn't destroyed either.
I have now leaked two Persons. I have no way to get them back but they exist forever (well, until program termination).