Not possible to free memory used by WASM (without using a web worker)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
It is desirable to be able to free up the 20MB+ allocated to the sql.js WASM in the JavaScript heap if this is only used for initial loading of data. This is not currently possible because the var initSqlJsPromise is held in a closure within the module and there is also no way to assign "undefined" to it once is no longer required (which would allow garbage collection to reclaim the memory). Although I can understand the desire to re-use the existing WASM if initSqlJs() is called more than once, the comment in the existing code hints at the undesirability of implementing it this way:
// TODO: Make this not declare a global if used in the browser
var initSqlJsPromise = undefined;
One solution (assuming exporting an additional function freeSqlJs() is problematic) would be to add a property in moduleConfig to optionally not hold a reference to initSqlJsPromise after initSqlJs() returns it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate initSqlJsPromise and moduleConfig in the JavaScript initialization code, then trace how the WASM instance is retained after initSqlJs() resolves. Review the existing reuse behavior and determine how an opt-out release mechanism should behave; done means the configured path no longer retains the unused WASM memory while normal repeated initialization remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, sqlite, wasm
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100