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

fix memory leak in wasm worker [#21] #22

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix memory leak in wasm worker [#21]
  • Loading branch information
bdon committed Feb 21, 2023
commit f248730bbbe24275bd9500fc46cfc3f1e8786359
7 changes: 7 additions & 0 deletions app/public/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ importScripts("sdfglyph.js");
self.onmessage = function (e) {
const fontstack_ptr = Module.ccall("create_fontstack", "number", [], []);

const font_datas = [];

for (let ab of e.data) {
let uint8Arr = new Uint8Array(ab);
const num_bytes = uint8Arr.length * uint8Arr.BYTES_PER_ELEMENT;
const data_ptr = Module._malloc(num_bytes);
font_datas.push(data_ptr);
const data_on_heap = new Uint8Array(
Module.HEAPU8.buffer,
data_ptr,
Expand Down Expand Up @@ -64,6 +67,10 @@ self.onmessage = function (e) {
]);
}

for (let data_ptr of font_datas) {
Module._free(data_ptr);
bdon marked this conversation as resolved.
Show resolved Hide resolved
}

Module._free(s);
Module.ccall("free_fontstack", "number", ["number"], [fontstack_ptr]);
};