ndarilek / tts-rs

115 stars 25 forks source link

WinRT doesn't correctly drop resources #54

Closed FrostyCoolSlug closed 7 months ago

FrostyCoolSlug commented 7 months ago

Hi there,

I've been using the TTS crate in one of my projects, and noticed that whenever a Tts object is dropped, it leaves behind MediaPlayer instances, seemingly not cleaning them up.

Example code to trigger:

fn main() {
    for _ in 0..5 {
        let mut tts = Tts::default().unwrap();
        let _ = tts.speak("Hello", false);
        sleep(Duration::from_secs(2));
        drop(tts);
    }

    sleep(Duration::from_secs(20));
}

The result is 5 MediaPlayer SMTC windows being left behind until the application exists: image

Tested on 0.26.0

FrostyCoolSlug commented 7 months ago

Did some digging, looks like this is a bug in windows::Media::Playback::MediaPlayer, and not tts-rs, neither calling .Close or dropping a MediaPlayer instance cleans up correctly. I'll close this.