Skip to content

Commit cc8d39c

Browse files
committed
docs: clarify explicitly freeing heap allocated memory
1 parent f1b104f commit cc8d39c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

library/alloc/src/boxed.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
10381038
/// use std::ptr;
10391039
///
10401040
/// let x = Box::new(String::from("Hello"));
1041-
/// let p = Box::into_raw(x);
1041+
/// let ptr = Box::into_raw(x);
10421042
/// unsafe {
1043-
/// ptr::drop_in_place(p);
1043+
/// ptr::drop_in_place(ptr);
10441044
/// dealloc(p as *mut u8, Layout::new::<String>());
10451045
/// }
10461046
/// ```
1047+
/// Note: This is equivalent to the following:
1048+
/// ```
1049+
/// let x = Box::new(String::from("Hello"));
1050+
/// let ptr = Box::into_raw(x);
1051+
/// drop(Box::from_raw(ptr));
1052+
/// ```
10471053
///
10481054
/// [memory layout]: self#memory-layout
10491055
#[stable(feature = "box_raw", since = "1.4.0")]

0 commit comments

Comments
 (0)