Skip to content

Commit

Permalink
docs: clarify explicitly freeing heap allocated memory
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalpharush committed Nov 4, 2023
1 parent f1b104f commit c7d8c65
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// use std::ptr;
///
/// let x = Box::new(String::from("Hello"));
/// let p = Box::into_raw(x);
/// let ptr = Box::into_raw(x);
/// unsafe {
/// ptr::drop_in_place(ptr);
/// dealloc(ptr as *mut u8, Layout::new::<String>());
/// }
/// ```
/// Note: This is equivalent to the following:
/// ```
/// let x = Box::new(String::from("Hello"));
/// let ptr = Box::into_raw(x);
/// unsafe {
/// ptr::drop_in_place(p);
/// dealloc(p as *mut u8, Layout::new::<String>());
/// drop(Box::from_raw(ptr));
/// }
/// ```
///
Expand Down

0 comments on commit c7d8c65

Please sign in to comment.