Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 408
Roee Gavirel Avatar asked May 23 '12 12:05

Roee Gavirel


People also ask

How does V8 garbage collection work?

The garbage collection process only starts when a new object comes in and find no more place for it in the from-space. Then it traverses a old-to new root set to figure out whether the object is still alive and whether it has been survived from the last round. If the object is no longer used, leave it there.

How do you invoke garbage collection?

Using Runtime. getRuntime(). gc() method: Runtime class allows the application to interface with the JVM in which the application is running. Hence by using its gc() method, we can request JVM to run Garbage Collector.

Can you invoke a garbage collector?

You can try to explicitly call the garbage collector by System. gc() and Runtime. gc(). However, even after explicitly calling the Garbage collector there is no guarantee that it will actually work.


2 Answers

  • 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
like image 58
Skomski Avatar answered Nov 15 '22 17:11

Skomski


Use V8::AdjustAmountOfExternalAllocatedMemory

http://create.tpsitulsa.com/wiki/V8/Garbage_Collection

like image 39
alexei-grigoriev Avatar answered Nov 15 '22 15:11

alexei-grigoriev