Skip to content

Remove reference to PostgresMod for long-running processes - #1073

Open
jdunck wants to merge 1 commit into
electric-sql:mainfrom
jdunck:free-enscripten
Open

Remove reference to PostgresMod for long-running processes#1073
jdunck wants to merge 1 commit into
electric-sql:mainfrom
jdunck:free-enscripten

Conversation

@jdunck

@jdunck jdunck commented Aug 3, 2026

Copy link
Copy Markdown

In a long-running process using many instances of pglite, we noticed that heap is never being freed. I believe this may be because .mod is holding a reference to the pg emscripten module.

I hope you'll agree this should be a safe change to make.

Screenshot 2026-08-03 at 4 52 16 PM

Around 14:45, there was a major GC but you can see no dropoff for the external space.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

* Throws if the module is not yet loaded, or has been released by `close()` -
* the Emscripten runtime is force-exited on close and cannot be revived.
*/
protected get mod(): PostgresMod {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to tidy the many mod!

// force-exited above and cannot be revived, so holding on to it only
// pins its heap (which can be hundreds of MB) for as long as this
// instance is referenced. Any later access throws via the `mod` getter.
this._mod = undefined

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the motivation for the change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant