Concurrent access atomicptr

I have an AtomicPtr reference that gets updated and read concurrently. What is the typical paradigm for managing it? I have set it up the following way:

let new = Box::into_raw(...);
let result = aptr.compare_exchange(old, new, ...);
match result {
     Ok(old) => {
            // add old to some epoch based garbage collector.
     Err(_) => {
            unsafe {new.drop_in_place()};

Unfortunately the Box creation seems to leak a helluva lot of memory. Any ideas what I might be doing wrong?

drop_in_place runs the destructor for the value inside the Box, it doesn't run Box's destructor. It can't because the pointer doesn't know anything about where it came from.

You should use Box::from_raw to drop the Box itself.