Skip to content

N-API: Lifetime of napi_env is unclear #31003

Closed
@argv-minus-one

Description

The N-API documentation says not to keep napi_env values around. This would seem to imply that napi_env values are valid only for the duration of a single call into native code (the module initializer, a native function call, etc).

However, in the C++ wrapper, the Reference class (which is meant to live longer than a single native call) keeps a long-lived napi_env value around, seemingly violating the documented lifetime!

Please clarify the lifetime of napi_env values in the documentation. Just how long is a napi_env really valid for? A single native call? The entire time until the env_shutdown_hooks are run and the native module is unloaded? Somewhere in between?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    node-apiIssues and PRs related to the Node-API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions