Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak? #1466

Open
shanliu opened this issue Sep 6, 2023 · 0 comments
Open

memory leak? #1466

shanliu opened this issue Sep 6, 2023 · 0 comments
Labels

Comments

@shanliu
Copy link

shanliu commented Sep 6, 2023

cargo.toml

[package]
name = "aaa"
version = "0.1.0"
edition = "2021"
[dependencies]
sled = "0.34.6"
memory-stats = "1.1.0"
humansize = "2.1.3"
use humansize::{format_size, DECIMAL};
fn main() {
    if let Some(usage) = memory_stats::memory_stats() {
        println!(
            "Current physical memory usage: {}",
            format_size(usage.physical_mem, DECIMAL)
        );
        println!(
            "Current virtual memory usage: {}",
            format_size(usage.virtual_mem, DECIMAL)
        );
    }

    aaaa();

    if let Some(usage) = memory_stats::memory_stats() {
        println!(
            "Current physical memory usage: {}",
            format_size(usage.physical_mem, DECIMAL)
        );
        println!(
            "Current virtual memory usage: {}",
            format_size(usage.virtual_mem, DECIMAL)
        );
    }
}

fn aaaa() {
    let temp_path = "D:/aaa/";
    println!("dir:{}", temp_path);
    // 使用 sled 创建一个数据库
    let config = sled::Config::new()
        .path(temp_path)
        .cache_capacity(1_000_000)
        .mode(sled::Mode::LowSpace)
        .temporary(true);
    let code_db = config.open().unwrap();
    drop(code_db);
    drop(config);
}

output:

Current physical memory usage: 3.87 MB
Current virtual memory usage: 851.97 kB
dir:D:/aaa/
Current physical memory usage: 27.41 MB
Current virtual memory usage: 23.55 MB

Why is the memory not freed when it's already drop db?

@shanliu shanliu added the bug label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant