-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what is heap::deallocate? #370
Comments
Notice the comment that says, "Wouldn't it be nice if |
If heap::deallocate is to free heap, why need to calling ptr::read which will also drop the memory |
@gftea Not every type implements |
@botahamec , thanks, but in our example, why
|
@gftea According to the comment, it is being used to drop the value, if needed. Just keep in mind that dropping the value doesn't free the memory that it's in. |
After the value drop, it should be uninitialized, we should not access it after that, so I think we should deallocate first before dropping ptr |
If you deallocate first, then how are you going to access the value so you can drop it? You don't have permission to use that part of the memory anymore. Besides, you don't have to access the value to deallocate memory. All you need is the pointer to where it was. |
sorry, I guess I did not understand above answer. |
That's mostly correct. |
after re-reading https://doc.rust-lang.org/nomicon/destructors.html, I think it will be more clear to explain further below
|
A example in https://github.com/rust-lang/nomicon/blob/master/src/leaking.md
heap::deallocate
in rust std library.heap::deallocate
is to free heap, why need to callingptr::read
which will also drop the memoryThe text was updated successfully, but these errors were encountered: