-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
docs: clarify explicitly freeing heap allocated memory #117563
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
ac47cd1
to
e45701f
Compare
This comment has been minimized.
This comment has been minimized.
e45701f
to
cc8d39c
Compare
This comment has been minimized.
This comment has been minimized.
cc8d39c
to
c7d8c65
Compare
@joboet can you elaborate on "whether it should be the other way around"? |
(for context: we were discussing this PR and a few others on Zulip) Mentioning the current example as an alternative should people who need to use the allocator themselves at ease, but IMHO most people should use drop(Box::from_raw(...)) since it avoids the pitfalls associated with the other version (thinking about it, there is actually a bug in it: if the destructor panics, the memory gets leaked). So the EDIT: Oh wait, that example is already given above. Then perhaps modifying the first example would make more sense? |
Hmm. I'm going to say "this seems wanted and I'm happy to review anyone's suggestions re: reorganizing it." @bors r+ rollup |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#116496 (Provide context when `?` can't be called because of `Result<_, E>`) - rust-lang#117563 (docs: clarify explicitly freeing heap allocated memory) - rust-lang#117874 (`riscv32` platform support) - rust-lang#118516 (Add ADT variant infomation to StableMIR and finish implementing TyKind::internal()) - rust-lang#118650 (add comment about keeping flags in sync between bootstrap.py and bootstrap.rs) - rust-lang#118664 (docs: remove rust-lang#110800 from release notes) - rust-lang#118669 (library: fix comment about const assert in win api) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117563 - 0xalpharush:docs/into-raw, r=workingjubilee docs: clarify explicitly freeing heap allocated memory The documentation for `Box::into_raw` didn't mention `drop` and wondered if I was doing something wrong. Based off [this](https://stackoverflow.com/questions/75441199/rust-how-do-i-correctly-free-heap-allocated-memory), I think it's helpful to include the more concise yet explicit way to free heap allocated memory. This is my first rust PR and I went through https://std-dev-guide.rust-lang.org/development/, but let me know if I missed something :)
The documentation for
Box::into_raw
didn't mentiondrop
and wondered if I was doing something wrong. Based off this, I think it's helpful to include the more concise yet explicit way to free heap allocated memory. This is my first rust PR and I went through https://std-dev-guide.rust-lang.org/development/, but let me know if I missed something :)