Skip to content

Stuck on dropping HashMap with numerous Vec<u8> exceeding 16KB on Windows #121747

@MrBeanCpp

Description

@MrBeanCpp

I tried this code:

let mut map = HashMap::new();
for i in 0..350000 {
    map.insert(i, vec![0u8; 1024 * 17]); //17KB
}
drop(map); //stuck here for a long time

I add println! before and after drop(map) , and it runs for a long time (more than couples of minutes).

But, if I change 1024 * 17 to 1024 * 16, then things will be different.

let mut map = HashMap::new();
for i in 0..350000 {
    map.insert(i, vec![0u8; 1024 * 16]); //16KB
}
drop(map); //1s

The drop(map) will end in just about 1 second!

But everything runs well on Linux, either 16KB or 17KB.

Is 16KB a magic number ?

But it doesn't make any sense why it's stuck and the memory usage(about 5.8GB) hasn't been continuously decreasing on Windows.

And if I change HashMap to Vec, it works well too.

let mut arr = Vec::new();
for i in 0..350000 {
    arr.push(vec![0u8; 1024 * 17]); //17KB
}
drop(arr); //fast

System Info

OS: Windows 11 22H2
CPU: 12th Gen Intel(R) Core(TM) i7-12700H   2.70 GHz
Memory: 32G (16G * 2)

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions