Closed as not planned
Description
my code
fn main() {
std::thread::sleep(std::time::Duration::from_secs(10));
loop {
test();
std::thread::sleep(std::time::Duration::from_secs(3));
}
}
struct MyVec {
vec: Vec<i32>,
}
impl Drop for MyVec {
fn drop(&mut self) {
println!("MyVec is being dropped, memory is being released.");
}
}
fn test() {
let mut my_vec = MyVec { vec: Vec::with_capacity(101) };
for i in 0..101 {
my_vec.vec.push(i);
}
println!("{:?}", my_vec.vec.len());
}
Run output
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
MyVec is being dropped, memory is being released.
101
Are these caused by dynamic memory allocation? If so, how should we deal with this situation? We can't let the memory grow indefinitely, can we? Or, the OS has its own recycling strategy, and when it reaches a certain size, it will be recycled. Can we set this value ourselves? Otherwise, we can't control the size of the program. Will there be memory leakage problems if the running time is long