V8 provides the v8::Isolate::low_memory_notification method, which is meant to let V8 know when the OS is running low on memory, so it can cause an aggressive, synchronous garbage collection. Currently Deno never calls this method, which can result in the OS killing the process when it's out of memory.
The question is when/how to know to call it.
Node.js seems to call into this method when an allocation in C++ fails, before trying again. In Rust this is not easy to do, because failed allocations will panic by default; APIs like Box::try_new can help, but they're still experimental, and we can't change every dependency to use them.
Chrome has a memory pressure monitor that seems to use OS signals to know the pressure level. It's not yet clear to me how (or whether) this signal ends up notifying V8, but I'm assuming that it does.
V8 provides the
v8::Isolate::low_memory_notification
method, which is meant to let V8 know when the OS is running low on memory, so it can cause an aggressive, synchronous garbage collection. Currently Deno never calls this method, which can result in the OS killing the process when it's out of memory.The question is when/how to know to call it.
Box::try_new
can help, but they're still experimental, and we can't change every dependency to use them.