Skip to content

[PHP] Find a way to shutdown the WASM module and reclaim memory #287

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

Closed
adamziel opened this issue May 10, 2023 · 2 comments
Closed

[PHP] Find a way to shutdown the WASM module and reclaim memory #287

adamziel opened this issue May 10, 2023 · 2 comments

Comments

@adamziel
Copy link
Collaborator

At the moment there is no way to shutdown the WASM runtime after it was started.

The following addition to the Emscripten module was insufficient to free the allocated memory:

/**
 * Expose a way to shut down the PHP runtime
 */
Module["exitRuntime"] = function () {
    exitRuntime();
    const empty = new ArrayBuffer([]);
    Module["HEAP8"].set(empty);
    Module["HEAP16"].set(empty);
    Module["HEAP32"].set(empty);
    Module["HEAPU8"].set(empty);
    Module["HEAPU16"].set(empty);
    Module["HEAPU32"].set(empty);
    Module["HEAPF32"].set(empty);
    Module["HEAPF64"].set(empty);
    
    updateGlobalBufferAndViews(empty);

    Module["HEAP8"] = HEAP8 = null;
    Module["HEAP16"] = HEAP16 = null;
    Module["HEAP32"] = HEAP32 = null;
    Module["HEAPU8"] = HEAPU8 = null;
    Module["HEAPU16"] = HEAPU16 = null;
    Module["HEAPU32"] = HEAPU32 = null;
    Module["HEAPF32"] = HEAPF32 = null;
    Module["HEAPF64"] = HEAPF64 = null;

    wasmTable = null;
    wasmMemory = null;
    wasmBinary = null;
    for (let key in Module["asm"]) {
        Module["asm"][key] = null
    }
    for (let key in Module) {
        if(key !== 'websocket') {
            Module[key] = null
        }
    }
}

Playground uses workers on every platform and then shuts down the entire worker thread so this issue has a very low priority for now.

@adamziel
Copy link
Collaborator Author

adamziel commented Oct 4, 2023

cc @seanmorris#639 PR solves this exact problem

@adamziel
Copy link
Collaborator Author

Solved in #639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant