Closed polin-x closed 1 year ago
Do you have more information on the leak by any chance?
Do you have more information on the leak by any chance?
How can I get it, I am not familiar with rust memory analysis
Valgrind or any equivalent will provide the information. I can't guess just from what you showed me.
It is caused by this line let mut sys = sysinfo::System::new_all(); I don’t know if the relevant memory needs to be released after use
Normally no, thanks to how Rust memory is managed. However, this is not this line but something allocated inside this method. Try running with more valgrind options to get a more precise location (normally valgrind suggests a few itself).
However, I still have no idea of your OS (even though I suppose it's Linux since you're using set_open_files_limit
).
Also a side-note: this code:
let mut sys = sysinfo::System::new_all();
sys.refresh_all();
std::thread::sleep(System::MINIMUM_CPU_UPDATE_INTERVAL);
sys.refresh_all();
can be reduced to:
let mut sys = sysinfo::System::new_all();
std::thread::sleep(System::MINIMUM_CPU_UPDATE_INTERVAL);
sys.refresh_all();
new_all
already get all updated information, so no need to call refresh_all
right after it.
I found that the same code works fine on macos (intel) and has problems on M1 Pro
That's weird. But in this case, I can't help since I don't have a M1...
I'll just change it to a different way of writing it.
lazy_static! {
static ref SYS: Mutex<System> = Mutex::new(System::new_all());
}
fn xxx() {
let mut sys = SYS.lock().unwrap();
sys.refresh_all();
drop(sys);
}
I couldn't find a leak so closing (on mac). Don't hesitate to re-open if you can find where it comes from.