Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Unbounded Memory Leak #106

@CraigMacomber

Description

@CraigMacomber

Describe the Bug

Making two large allocations, then dropping them in the order they were allocated leaks memory in wee_alloc, but not in default allocator.

Steps to Reproduce

Native code

  1. Clone this branch of my app: https://github.com/CraigMacomber/wee_alloc_leak_png
  2. cargo run
  3. GB of memory is consumed per second
  4. Comment out use of wee_alloc global_allocator.
  5. cargo run
  6. Memory use does not increase.

Wasm

  1. Clone this branch of my app: https://github.com/noencke/uuid-cluster/tree/wee_alloc_leak
  2. npm run serve (runs wasm-pack, npm install and webpack dev server)
  3. go to localhost:8080 in browser
  4. click the button (it's the only thing on the page) to increase heap by 131 MB each time

Expected Behavior

Second time allocations are made uses free list.

Actual Behavior

Repeated allocations grow heap infinitely.

Additional Context

This seems similar to an issue mentioned in #105
Heap size does not increase if using default allocator.

Rust source for example is just:

extern crate wee_alloc;

// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

pub fn leak_test() {
    // This leaks when using wee_alloc
    let a = Box::new([0; 85196]);
    let b = Box::new([0; 80000]);
    drop(a);
    drop(b);
}

fn main() {
    loop {
        leak_test();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions