yalishandar / tasklist-rs

Get the process name or process id on windows
19 stars 3 forks source link

Potential Memory Leak in tasklist Usage (looping process list) #6

Open xh0 opened 4 months ago

xh0 commented 4 months ago

I'm using the tasklist crate to list running processes in a loop. Here's a minimal example showcasing the issue:

use tasklist;

fn main() {
    loop {
        std::thread::sleep(std::time::Duration::from_millis(10_000));
        unsafe {
            let tl = tasklist::Tasklist::new();
            for i in tl {
                println!("{} {} {}", i.get_pid(), i.get_pname(), i.get_user());
            }
        }
    }
}

I've observed that the memory usage of this application keeps increasing over time. This leads me to believe there might be a memory leak in how the tasklist crate is being used.

Additional Information:

I'm using tasklist version 0.2.13. I've included a minimal example to isolate the issue.

Possible Cause:

I'm not entirely sure, but the usage of unsafe block and the loop might be causing the leak. The tasklist crate might be allocating memory for each iteration that's not being properly released.

Request:

I'd appreciate it if you could investigate this potential memory leak. If it's confirmed, any suggestions on how to use tasklist more efficiently or alternative approaches to achieve the same functionality would be helpful.

Thank you!

yalishandar commented 2 months ago

I upgraded the referenced windows-sys crate to the latest version, please check whether this phenomenon still occurs.