v8 | manually initiate the garbage collector

c++, garbage-collection, v8

Solution

You can expose the `v8::HEAP->CollectAllGarbage` function to the global JavaScript namespace via the command flag `--expose_gc`. Then simply call `gc();`.

You can force garbage collection from C++ via the statement:

`while(!V8::IdleNotification()) {};`

References:

- http://code.google.com/p/v8/source/browse/trunk/src/extensions/gc-extension.cc

- http://code.google.com/p/v8/issues/detail?id=1688

Problem

Is there a way to manually initiate the garbage collector on Google's V8 engine? I couldn't find any reference for it. by usually GCs support this function.

Original source