Open
Description
In Rust 1.65.0 and x86_64-unknown-linux-gnu build, debian 11.2
use std::{time::Duration, io::Write};
use std::net::TcpStream;
fn main() {
// now memory is 5m
std::thread::sleep(Duration::new(5, 0));
{
for i in 1..10 {
// any redis clint
let mut tcp = TcpStream::connect("127.0.0.1:6379").unwrap();
let data: Vec<u8> = vec![49; 26748528];
let _ = tcp.write_all(&data);
std::thread::sleep(Duration::new(5, 0));
}
}
// now memory is 27m
std::thread::sleep(Duration::new(500, 0));
}
I expected to see this happen: every once run
When I run multi thread, It will increase too much memory. just like
use std::thread;
use std::{time::Duration, io::Write};
use std::net::TcpStream;
fn main() {
// now memory is 5m
std::thread::sleep(Duration::new(5, 0));
for thread_id in 1 .. 10 {
thread::spawn(move || {
{
for i in 1..10 {
// any redis clint
let mut tcp = TcpStream::connect("127.0.0.1:6379").unwrap();
let data: Vec<u8> = vec![i + 49; 26748528];
let _ = tcp.write_all(&data);
std::thread::sleep(Duration::new(5, 0));
}
println!("end thread {}", thread_id);
}
});
}
println!("end this block");
// now memory is 237m
std::thread::sleep(Duration::new(500, 0));
}
So my project offten out of memory by this reason. Why This cache so much memory?
In windows or macos, this memory is reduce when thread close.