Search code examples
javascriptpythongarbage-collectionv8pyv8

PyV8 disable automatic garbage collection


I'm having an issue which seems to be related with the way Python & PyV8's garbage collection interact. I've temporarily solved the issue by disabling python's garbage collection, and calling gc.collect and PyV8.JSEngine.collect together every few seconds when no JavaScript is being run. However, this seems like a pretty hackish fix... in particular, I'm worried PyV8 might decide to collect at an inopportune time and cause problems, anyway. Is there any way to disable PyV8's automatic garbage collection for good, at least until I have a few days to spend figuring out exactly what is going on and thus to actually fix the issue?


Solution

  • It's possible to disable garbage collection for good by changing the source code of V8.

    In V8's source, edit src/heap.cc, and put a return statement in the beginning of Heap::CollectGarbage.

    Other than that, it's not possible (AFAICT): V8 will always invoke garbage collection when it's about to run out of memory. There is no (configurable) way to not have it do that.