Skip to content

Clarification suggestion: Distinction between references and ownership in pointer deallocation danger. #379

@matiscodjia

Description

@matiscodjia

Hi! I'm currently studying the section on "Aliasing and Mutation" in the Rust Book Experiment, and I noticed a phrasing that might be slightly misleading for students.

"Pointers are a powerful and dangerous feature because they enable aliasing... One variable can 'pull the rug out' from another variable in many ways, for example: By deallocating the aliased data, leaving the other variable to point to deallocated memory."

The Point of Confusion: In Rust, a reference (&T or &mut T) does not own the data it points to and therefore cannot deallocate it. The current wording might lead a student to believe that a reference itself has the power to trigger a deallocation.

Suggested Improvement: To reinforce the core concept of Ownership, it might be clearer to specify that it is the owner (or a smart pointer like Box) that performs the deallocation, which then affects any existing aliases. Perhaps something like:

"By having the owner deallocate the aliased data (for instance, through a mutation like vec.push() or by dropping the owner), leaving any existing references to point to invalidated memory."

Why it matters: This distinction helps the student visualize the reference as a passive victim of the owner's actions. It reinforces the mental model that while a reference is an observer, it is entirely dependent on the owner's stability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions