cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Memory leak in WASAPI `input_devices`

Open nicolaiunrein opened this issue 2 years ago • 2 comments

The below code is causing a memory leak on my machine:

use cpal::traits::HostTrait;

fn main() {
    let host = cpal::ALL_HOSTS
        .into_iter()
        .find(|id| id.name() == "WASAPI")
        .and_then(|id| cpal::host_from_id(*id).ok())
        .expect("No WASAPI host found");

    loop {
        let _ = host.input_devices().unwrap().collect::<Vec<_>>();
        std::thread::sleep(std::time::Duration::from_millis(10));
    }
}

System Info

  • OS: Running Microsoft Windows 11 Pro
  • Version: 10.0.22621 Build 22621
  • cpal version: 0.15.2
  • Toolchain: stable-x86_64-pc-windows-msvc

rustc -Vv output

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-pc-windows-msvc
release: 1.72.0
LLVM version: 16.0.5

nicolaiunrein avatar Oct 13 '23 10:10 nicolaiunrein

I am experiencing the same issue

System Info

  • OS: Windows 11 Home
  • Version: 23H2 Build 22631.3737
  • cpal version: 0.15.3
  • Toolchain: stable-x86_64-pc-windows-msvc

rustc -Vv output

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-pc-windows-msvc
release: 1.78.0
LLVM version: 18.1.2

chanderlud avatar Jun 26 '24 00:06 chanderlud

I don't think this is fixed yet. Memory keeps constantly increasing if I run

if let Ok(devices) = host.input_devices() {
            for device in devices {
           self.input_device_names.push(device);
}

in a loop the memory keeps increasing and doesn't come down

kaundinya5 avatar May 30 '25 11:05 kaundinya5