too-many-lists icon indicating copy to clipboard operation
too-many-lists copied to clipboard

Clarifying where and why pop deallocates first node from the heap

Open GregDavidson opened this issue 5 years ago • 1 comments

In https://rust-unofficial.github.io/too-many-lists/first-pop.html I would appreciate clarification on exactly where and why the first node on the list gets deallocated from the heap by pop after pop uses mem::replace or take. I'm loving your tutorial and I'm hoping to get more clarity on Rust's deallocation strategies.

GregDavidson avatar Sep 30 '19 04:09 GregDavidson

I'm actually not 100% certain, because iirc this code uses the obscure and 100% special DerefMove semantics of Box that allow the allocation to be partially moved out of. I would expect the deallocation to happen at the end of the scope, but wouldn't be surprised if it happens earlier.

Gankra avatar Oct 04 '19 15:10 Gankra