uvcc
libuv C++ bindings
Destroy callbacks

The following libuv types provide a field which is a pointer to the user-defined arbitrary data that can be associated with the libuv object:

Each of the uvcc classes representing these libuv types provides a destroy callback that is called when the reference count for the object instance becomes zero:

The callback is intended to give the option to manipulate the user-defined data associated with the object through the .data pointer before the last variable referencing this object has been destroyed.

For the uv::handle calss the destroy callback functionality was initially based on the underlying libuv API uv_close_cb facilities. The handle close callback passed to uv_close() goes through the event loop and is called asynchronously after the uv_close() call. But it wouldn't be executed if the loop with which the handle to be closed is associated is not running e.g. because of the loop has exited after processing all active handles and requests, and the program has come to the end (in this case the special care should be taken for proper closing of the libuv loop so all the pending callbacks to be performed). Instead, uvcc's destroy callback is called in any case when the last variable referencing this handle is destroyed. Whether the loop is running or not, the destroy callback will be executed synchronously as integrated part of the handle instance closing procedure.

For the other two classes (uv::request and uv::loop) the destroy callbacks are a uvcc specific feature and they are executed as integrated part of the variable's destructor.