Skip to content

Commit

Permalink
doc: added some warnings for buffer and array buffer factory method. (#…
Browse files Browse the repository at this point in the history
…929)

* Fixes issue 258.
  • Loading branch information
NickNaso authored Mar 22, 2021
1 parent 6490b1f commit 8ef0725
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/array_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ The `Napi::ArrayBuffer` instance does not assume ownership for the data and
expects it to be valid for the lifetime of the instance. Since the
`Napi::ArrayBuffer` is subject to garbage collection this overload is only
suitable for data which is static and never needs to be freed.
This factory method will not provide the caller with an opportunity to free the
data when the `Napi::ArrayBuffer` gets garbage-collected. If you need to free
the data retained by the `Napi::ArrayBuffer` object please use other
variants of the `Napi::ArrayBuffer::New` factory method that accept
`Napi::Finalizer`, which is a function that will be invoked when the
`Napi::ArrayBuffer` object has been destroyed.
```cpp
static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength);
Expand Down
6 changes: 6 additions & 0 deletions doc/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ The `Napi::Buffer` object does not assume ownership for the data and expects it
valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
collection this overload is only suitable for data which is static and never
needs to be freed.
This factory method will not provide the caller with an opportunity to free the
data when the `Napi::Buffer` gets garbage-collected. If you need to free the
data retained by the `Napi::Buffer` object please use other variants of the
`Napi::Buffer::New` factory method that accept `Napi::Finalizer`, which is a
function that will be invoked when the `Napi::Buffer` object has been
destroyed.
```cpp
static Napi::Buffer<T> Napi::Buffer::New(napi_env env, T* data, size_t length);
Expand Down

0 comments on commit 8ef0725

Please sign in to comment.