Skip to content

Commit 87b7aae

Browse files
authored
doc: warn about SuppressDestruct() (#926)
Not sure how this ever made its way into the API, but people should *never* use this.
2 parents 71494a4 + 69d0d98 commit 87b7aae

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

doc/reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Holds a counted reference to a [`Napi::Value`](value.md) object; initially a wea
44

55
The referenced `Napi::Value` is not immediately destroyed when the reference count is zero; it is merely then eligible for garbage-collection if there are no other references to the `Napi::Value`.
66

7-
`Napi::Reference` objects allocated in static space, such as a global static instance, must call the `SuppressDestruct` method to prevent its destructor, running at program shutdown time, from attempting to reset the reference when the environment is no longer valid.
7+
`Napi::Reference` objects allocated in static space, such as a global static instance, must call the `SuppressDestruct` method to prevent its destructor, running at program shutdown time, from attempting to reset the reference when the environment is no longer valid. Avoid using this if at all possible.
88

99
The following classes inherit, either directly or indirectly, from `Napi::Reference`:
1010

@@ -109,3 +109,5 @@ void Napi::Reference::SuppressDestruct();
109109
```
110110

111111
Call this method on a `Napi::Reference` that is declared as static data to prevent its destructor, running at program shutdown time, from attempting to reset the reference when the environment is no longer valid.
112+
113+
Avoid using this if at all possible. If you do need to use static data, **MAKE SURE** to warn your users that your addon is **NOT** threadsafe.

napi.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,11 @@ namespace Napi {
11751175
void Reset();
11761176
void Reset(const T& value, uint32_t refcount = 0);
11771177

1178-
// Call this on a reference that is declared as static data, to prevent its destructor
1179-
// from running at program shutdown time, which would attempt to reset the reference when
1180-
// the environment is no longer valid.
1178+
// Call this on a reference that is declared as static data, to prevent its
1179+
// destructor from running at program shutdown time, which would attempt to
1180+
// reset the reference when the environment is no longer valid. Avoid using
1181+
// this if at all possible. If you do need to use static data, MAKE SURE to
1182+
// warn your users that your addon is NOT threadsafe.
11811183
void SuppressDestruct();
11821184

11831185
protected:

0 commit comments

Comments
 (0)