mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
docs: clarify explicitly freeing heap allocated memory
This commit is contained in:
parent
f1b104f523
commit
c7d8c65c1a
@ -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(p);
|
||||
/// dealloc(p as *mut u8, Layout::new::<String>());
|
||||
/// 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 {
|
||||
/// drop(Box::from_raw(ptr));
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user