emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1.01k stars 97 forks source link

Memory leak when creating a new window #357

Open shassen14 opened 1 month ago

shassen14 commented 1 month ago

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!

emoon commented 1 month ago

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.