Skip to content

Clarify Vec's documentation about buffer reuse #84488

Closed
@comex

Description

@comex

The documentation for Vec states:

Do not rely on removed data to be erased for security purposes. Even if you drop a Vec, its buffer may simply be reused by another Vec.

Here, "its buffer may simply be reused" is simply meant to refer to the behavior of the underlying allocator. But I have seen people with low-level experience be misled by this into thinking that the implementation of Vec itself has its own global allocation cache. They then thought this cache was responsible for excess memory usage in their programs.

I'm not sure what the best way to clarify this would be. Part of the reason the current wording can be misleading is that "reused by another Vec" suggests a mechanism specific to Vec. On the other hand, it would also help to just explicitly mention the allocator. Here is a possible version that addresses both points, but it's more wordy than the current version:

Even if you drop a Vec, the allocator may reuse its buffer for another Vec or other allocation.

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions