flo_draw icon indicating copy to clipboard operation
flo_draw copied to clipboard

possible memory leak?

Open polymorphicengine opened this issue 1 month ago • 3 comments

Hi, I'm encountering what seems to be a slight memory leak (?) with flo_draw = "0.3.1" and flo_canvas = "0.3.1"). I'm trying to do a simple animation by looping the canvas.draw function. This will steadily consume memory (not a lot, only about 0.2 mega byte per second), but i want my application to be able to run for very long periods (days) and i'm worried it will run out of memory eventually. Here is a very simple piece of code that also produces the issue, am I doing something wrong?

use flo_canvas::*;
use flo_draw::*;

use std::thread;
use std::time::Duration;

pub fn main() {
    with_2d_graphics(|| {
        let canvas = create_drawing_window("Window");
        canvas.draw(|gc| {
            gc.clear_canvas(Color::Rgba(0.6, 0.7, 0.8, 1.0));
            gc.canvas_height(1000.0);
            gc.center_region(0.0, 0.0, 1000.0, 1000.0);
        });
        loop {
            canvas.draw(|gc| {
                gc.layer(LayerId(1));
                gc.clear_layer();
                gc.rect(0.0, 0.0, 100.0, 100.0);
                gc.fill_color(Color::Rgba(0.0, 0.0, 0.0, 1.0));
                gc.fill();
            });
            thread::sleep(Duration::from_nanos(1_000_000_000 / 60));
        }
    });
}

polymorphicengine avatar Dec 02 '25 09:12 polymorphicengine