Skip to content

JS High-level api - Memory cleanup #7427

@HalfdanJ

Description

@HalfdanJ

I've noticed that in the js high level api, memory of some object will never be freed from the wasm memory until the api shuts down and garbage collects. This works fine in short-lived applications, but if the library is used in a long living application where new variables / solvers / functions whatnot are created dynamically, there is to my knowledge no way to free up the memory it allocates.

Currently all cleanup callbacks are registered on the createApi instance https://github.com/Z3Prover/z3/blob/master/src/api/js/src/high-level/high-level.ts#L118, and i'm trying to understand why its not either registered on the individual context the object is created within (so you can garbage collect an entire context and cleanup its associated memory), or individually on the objects that are allocating the memory.
For example, why not register FinalizationRegistry on Solver class itself, so if nothing points to an instance of Solver, it will allow the memory to be freed from the wasm memory.

Am I missing something that wont make that possible?

Tagging @bakkot / @ritave since this design mostly comes from you?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions