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

Add an option to expose global.gc(). #1213

Closed
bolinfest opened this issue Mar 6, 2015 · 5 comments
Closed

Add an option to expose global.gc(). #1213

bolinfest opened this issue Mar 6, 2015 · 5 comments

Comments

@bolinfest
Copy link

Node accepts the --expose-gc flag to make global.gc() available. I am trying to write some tests using WeakMap to see if I have memory leaks, so having access to global.gc() would be really useful.

Is there any way to enable this today and/or how hard would it be to add?

@deepak1556
Copy link
Member

v8 related flags can be enabled by https://github.com/atom/atom-shell/blob/master/spec/static/main.js#L9 but it actually didnt expose gc() . is it because v8 was already initialised by gin in libchromium, @zcbenz thoughts ?

@zcbenz
Copy link
Member

zcbenz commented Mar 9, 2015

@deepak1556 That code is in the specs window.

@bolinfest You can use the line referenced by @deepak1556 to expose gc.

@zcbenz zcbenz closed this as completed Mar 9, 2015
@bradisbell
Copy link

Could someone please elaborate on how to actually expose global.gc() in Electron? The link above doesn't seem to reference anything useful anymore.

@danburzo
Copy link
Contributor

danburzo commented Oct 13, 2016

@bradisbell you need to run Electron with --js-flags="--expose-gc" to enable the global.gc() method. I've made a pull request to clarify the docs for command-line switches.

@cbroad
Copy link

cbroad commented Jul 15, 2021

This is only about 5 years late, but for posterity the following can be done without any command line args. The "--expose-gc" command line argument is implied in the first command.

require("v8").setFlagsFromString("--expose_gc");
global.gc = require("vm").runInNewContext("gc");

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

No branches or pull requests

6 participants