Skip to content

Conversation

@alex1bondoc
Copy link

The original explanation of Rust's dropping behavior contained an error that could lead to misunderstandings:

It stated that "the struct itself is dropped first, then its children are dropped individually". This is incorrect because Rust ensures that fields (children) are dropped first, followed by the struct itself.
The explanation also lacked an example to demonstrate the correct behavior, which could help clarify this important concept for readers.

* By automatically freeing memory Rust helps ensure that there are fewer
memory leaks.
* Rust ensures safe and predictable cleanup by dropping fields before the
Copy link
Contributor

@alexandruradovici alexandruradovici Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, please take a look at the Drop trait.

content_markdown: >
When a struct is dropped, the struct itself is dropped first, then its
children are dropped individually, and so on.
When a struct is dropped, its fields (children) are dropped first, in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, take a look at the Drop trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants