Skip to content

Commit 8ef0725

Browse files
authored
doc: added some warnings for buffer and array buffer factory method. (#929)
* Fixes issue 258.
1 parent 6490b1f commit 8ef0725

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

doc/array_buffer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ The `Napi::ArrayBuffer` instance does not assume ownership for the data and
2929
expects it to be valid for the lifetime of the instance. Since the
3030
`Napi::ArrayBuffer` is subject to garbage collection this overload is only
3131
suitable for data which is static and never needs to be freed.
32+
This factory method will not provide the caller with an opportunity to free the
33+
data when the `Napi::ArrayBuffer` gets garbage-collected. If you need to free
34+
the data retained by the `Napi::ArrayBuffer` object please use other
35+
variants of the `Napi::ArrayBuffer::New` factory method that accept
36+
`Napi::Finalizer`, which is a function that will be invoked when the
37+
`Napi::ArrayBuffer` object has been destroyed.
3238
3339
```cpp
3440
static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength);

doc/buffer.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ The `Napi::Buffer` object does not assume ownership for the data and expects it
2828
valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
2929
collection this overload is only suitable for data which is static and never
3030
needs to be freed.
31+
This factory method will not provide the caller with an opportunity to free the
32+
data when the `Napi::Buffer` gets garbage-collected. If you need to free the
33+
data retained by the `Napi::Buffer` object please use other variants of the
34+
`Napi::Buffer::New` factory method that accept `Napi::Finalizer`, which is a
35+
function that will be invoked when the `Napi::Buffer` object has been
36+
destroyed.
3137
3238
```cpp
3339
static Napi::Buffer<T> Napi::Buffer::New(napi_env env, T* data, size_t length);

0 commit comments

Comments
 (0)