Skip to content

Reuse freed allocations in WebAssembly linear memory #700

Closed

Description

@LunaStev

Problem

The wasm32 and Memory64 providers use bump allocators. sys_free validates basic arguments but does not reclaim or reuse the allocation. This is an intentional initial limitation, documented in std/sys/wasm/memory.wave, rather than a newly introduced regression.

Repeated allocation/free and portable buffer resizing can therefore consume linear memory even when live storage stays bounded.

Scope

Add reuse of freed allocations to the single-threaded WebAssembly allocators while preserving the existing sys_alloc(size) / sys_free(pointer, size) API and target pointer widths. Reclaiming here means reusing linear-memory space; it does not require shrinking WebAssembly memory or returning pages to the host.

Completion criteria

  • Repeated same-size allocate/free workloads reach a bounded memory plateau.
  • Mixed sizes can reuse freed storage with suitable splitting and coalescing, or an explicitly bounded alternative.
  • Live allocations never overlap and retain their contents across allocator activity.
  • Preserve at least the current 16-byte alignment and allocation-failure behavior.
  • Check metadata arithmetic, memory growth failure, and wasm32 address limits without narrowing Memory64 pointers.
  • Document allocator ownership and the pointer/size requirements for freeing.
  • Test wasm32 unknown/WASI and wasm64 unknown execution, including buffer reallocation, zero/invalid sizes, and fragmentation.
  • Do not add libc or another allocator dependency.

Difficulty: high. This is not a good first issue. Separate from #466 (wasm64 WASI ABI), #532 (async watch ownership), and #676 (buffer source alias classification).

Activity

  1. added
    enhancement
    help wanted
    performance
    needs testing
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wantedneeds testingperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions