Search code examples
c++garbage-collectionv8

v8 | manually initiate the garbage collector


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.


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: