Nan::PersistentBase & v8::PersistentBase
- Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits
- Nan::CopyablePersistentTraits & v8::CopyablePersistentTraits
- Nan::Persistent
- Nan::Global
- Nan::WeakCallbackInfo
- Nan::WeakCallbackType
Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://developers.google.com/v8/embed#handles).
### Nan::PersistentBase & v8::PersistentBase
A persistent handle contains a reference to a storage cell in V8 which holds an object value and which is updated by the garbage collector whenever the object is moved. A new storage cell can be created using the constructor or `Nan::PersistentBase::Reset()`. Existing handles can be disposed using an argument-less `Nan::PersistentBase::Reset()`.
Definition:
_(note: this is implemented as `Nan::PersistentBase` for older versions of V8 and the native `v8::PersistentBase` is used for newer versions of V8)_
```c++
template::Callback callback,
WeakCallbackType type);
void ClearWeak();
/**
* Marks the reference to this object independent. Garbage collector is free
* to ignore any object groups containing this object. Weak callback for an
* independent handle should not assume that it will be preceded by a global
* GC prologue callback or followed by a global GC epilogue callback.
*/
void MarkIndependent() const;
bool IsIndependent() const;
/** Checks if the handle holds the only reference to an object. */
bool IsNearDeath() const;
/** Returns true if the handle's reference is weak. */
bool IsWeak() const
};
```
See the V8 documentation for [`PersistentBase`](https://v8docs.nodesource.com/io.js-3.0/d4/dca/classv8_1_1_persistent_base.html) for further information.
### Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits
Default traits for `Nan::Persistent`. This class does not allow use of the a copy constructor or assignment operator. At present `kResetInDestructor` is not set, but that will change in a future version.
Definition:
_(note: this is implemented as `Nan::NonCopyablePersistentTraits` for older versions of V8 and the native `v8::NonCopyablePersistentTraits` is used for newer versions of V8)_
```c++
template &source,
NonCopyablePersistent *dest);
template &source,
CopyablePersistent *dest);
};
```
See the V8 documentation for [`CopyablePersistentTraits`](https://v8docs.nodesource.com/io.js-3.0/da/d5c/structv8_1_1_copyable_persistent_traits.html) for further information.
### Nan::Persistent
A type of `PersistentBase` which allows copy and assignment. Copy, assignment and destructor behavior is controlled by the traits class `M`.
Definition:
```c++
template that);
/**
* Construct a Persistent from a Persistent. When the Persistent is non-empty,
* a new storage cell is created pointing to the same object, and no flags are
* set.
*/
Persistent(const Persistent &that);
/**
* The copy constructors and assignment operator create a Persistent exactly
* as the Persistent constructor, but the Copy function from the traits class
* is called, allowing the setting of flags based on the copied Persistent.
*/
Persistent &operator=(const Persistent &that);
template &that);
/**
* The destructor will dispose the Persistent based on the kResetInDestructor
* flags in the traits class. Since not calling dispose can result in a
* memory leak, it is recommended to always set this flag.
*/
~Persistent();
};
```
See the V8 documentation for [`Persistent`](https://v8docs.nodesource.com/io.js-3.0/d2/d78/classv8_1_1_persistent.html) for further information.
### Nan::Global
A type of `PersistentBase` which has move semantics.
```c++
template that);
/**
* Construct a Global from a PersistentBase. When the Persistent is non-empty,
* a new storage cell is created pointing to the same object, and no flags are
* set.
*/
template &that);
/**
* Pass allows returning globals from functions, etc.
*/
Global Pass();
};
```
See the V8 documentation for [`Global`](https://v8docs.nodesource.com/io.js-3.0/d5/d40/classv8_1_1_global.html) for further information.
### Nan::WeakCallbackType
### Nan::WeakCallbackInfo
`Nan::WeakCallbackInfo` is used as an argument when setting a persistent reference as weak. You may need to free any external resources attached to the object. It is a mirror of `v8:WeakCallbackInfo` as found in newer versions of V8.
Definition:
```c++
template