rust_minifb icon indicating copy to clipboard operation
rust_minifb copied to clipboard

Memory leak when creating a new window

Open shassen14 opened this issue 1 year ago • 1 comments

I noticed a small memory leak while developing and tracked it down partially due to when creating a new window. Here is an example code which valgrind detects a memory leak. I am on Ubuntu 22.04 testing this.

use minifb::{Window, WindowOptions};

const W: usize = 800;
const H: usize = 400;

fn main() -> Result<(), std::io::Error> {
    let _window = Window::new(
        &"Here is a title".to_string(),
        W,
        H,
        WindowOptions::default(),
    );

    Ok(())
}

The output text from valgrind is attached here. test_minifb.txt

Valgrind states there is 244 bytes lost in this program, but the program I was developing was integrating minifb and plotters stated there was 500 bytes lost. I am currently trying to track down the other 256 bytes (and also if it grows over time).

If there is something I am doing wrong or more information needed, I would greatly appreciate any feedback. Thank you so much for your work!

shassen14 avatar Aug 05 '24 19:08 shassen14

Thanks for the report. It might be related to some resources that isn't freed correctly during the close down of the Window. While not ideal as long as it doesn't keep leaking while running it shouldn't be a major issue as the OS will clean up the resources afterwards.

That being said it would be nice to fix it if possible.

emoon avatar Aug 09 '24 08:08 emoon