alexcrichton / tar-rs

Tar file reading/writing for Rust
https://docs.rs/tar
Apache License 2.0
616 stars 178 forks source link

Memory leaks #354

Open Smotrov opened 5 months ago

Smotrov commented 5 months ago

I know it is always strange to talk about memory leaks in Rust. But anyway... My app is constantly working with queue of tar files with about 10K entries. And the memory used is slowly growing over time for no reason. After investigation with Xcode instruments it showed that there is a memory leak on the very simple line entry.read_to_end(&mut buff_vec)?;

Has anybody faced the same problem?

Знімок екрана 2024-02-14 о 12 14 13

Any ideas how to address that?

NobodyXu commented 5 months ago

Add buff_vec.shrink_to_fit() before inserting into the HashMap, it would remove the unused capacity in the Vec reserved (to achieve amortised O(1) push).

Smotrov commented 5 months ago

Add buff_vec.shrink_to_fit() before inserting into the HashMap, it would remove the unused capacity in the Vec reserved (to achieve amortised O(1) push).

Thank you. Unfortunately does not helps.