mooman219 / fontdue

The fastest font renderer in the world, written in pure rust.
Apache License 2.0
1.38k stars 70 forks source link

Memory isn't freed when Font is dropped #110

Closed MarcusGrass closed 2 years ago

MarcusGrass commented 2 years ago

On x86_64-unknown-linux-gnu memory is not freed when a loaded font is dropped, minimal repro.

use fontdue::{Font, FontSettings};

fn main() {

    // Your font below
    let font = "../font.ttf";
    let font_bytes = std::fs::read(font).unwrap();
    let font = Font::from_bytes(font_bytes.as_slice(), FontSettings::default()).unwrap();

    drop(font);
    drop(font_bytes);

    loop {

    }
}

Running smem on that gives about 18M; pmap shows image Where the 17+M is the font footprint in memory.

use fontdue::{Font, FontSettings};

fn main() {

    // Your font below
    let font = "../font.ttf";
    let font_bytes = std::fs::read(font).unwrap();
    //let font = Font::from_bytes(font_bytes.as_slice(), FontSettings::default()).unwrap();
    //drop(font);
    drop(font_bytes);

    loop {

    }
}

Running smem on that gives about 532K. Dropping or not dropping the font has no impact on memory usage.

I might be doing something dumb and not realizing it, or memory is not released when the Font struct is dropped for some reason.

MarcusGrass commented 2 years ago

My bad, it's the massive amounts of Vec on each glyph that takes up a lot of space and memory reclamation seems to be slow in my case