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

Allocation memory change from 0 to some bytes at 4783 iteration #150

Open
allevo opened this issue May 14, 2020 · 0 comments
Open

Allocation memory change from 0 to some bytes at 4783 iteration #150

allevo opened this issue May 14, 2020 · 0 comments

Comments

@allevo
Copy link

allevo commented May 14, 2020

Hi!

I've a memory leak in an application. After some search I found this crate and restrict the area of my problem.
After some tries I have a strange behavior:

use jemalloc_ctl::{stats, epoch};
use jemallocator;
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    let my_structs = vec![3];

    let allocated_bytes: usize = current();
    {
        for _i in 0..4782 {
            let _a: Vec<&i32> = my_structs
                .iter()
                .collect();
        }
    } // here dealloc all variables

    let allocated_bytes_after: usize = current();
    println!("before allocated_bytes: {}", allocated_bytes);
    println!("after   allocated_bytes: {}", allocated_bytes_after);
    println!("DIFF allocated_bytes: {}", allocated_bytes_after - allocated_bytes);

    Ok(())
}

fn current() -> usize {
    epoch::advance().unwrap();
    stats::allocated::read().unwrap()
}

The code above runs correctly printing 0 bytes as diff. On my PC the output is:

before allocated_bytes: 244960
after  allocated_bytes: 244960
DIFF allocated_bytes: 0

Anyway changing the magic number from 4782 to 4783, the program exits with panic because the difference is less than 0.

before allocated_bytes: 244960
after  allocated_bytes: 244376
thread 'main' panicked at 'attempt to subtract with overflow', src/main.rs:23:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Panic in Arbiter thread.

I don't know if this problem is linked to my origina one but this behavior is very strange and I would like to report it here.

Why the allocation change from 4782 to 4783? Why 4783?

I'm using:

$ cargo version
cargo 1.43.0 (2cbe9048e 2020-05-03)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant