nodejs / node-addon-api

Module for using Node-API from C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are native addons affected by Node's max memory size constraint?

alshdavid opened this issue · comments

If I allocate values in a Node addon, say a vector of structs that ends up 10gb, would the memory allocated in the Node addon be restricted by the memory limit of the Node.js process or does it have a separate heap?

When exposing values from the node addon to Node.js, are the values copied to the JS heap?

If you allocate native objects they don't consume space in the JavaScript heap. However if you use the node-apis to create JavaScript functions/objects (for example a long JavaScript string) then all of the memory they use do come from the JavaScript heap.

You can provide a hint of native memory you have allocated through napi_adjust_external_memory but that does not affect how much you can allocate from the JavaScript heap, only provides info that the gc might use to decide to try to run gc earlier than it would otherwise on the assumption that some of that native memory might be held alive indirectly through objects that are on the Heap. For example if you create a Reference to native memory, then add that Reference to a JavaScript Object, the native memory is held alive indirect by the Object being alive on the JavaScript heap.

I'm going to close this as answered. Please let us know if that was not the right thing to do.