OpenNI 1.0.0
Reference Counting

OpenNI uses reference counting for nodes. This is needed because several nodes might depend on the same node. When a node is created, it has a reference count of 1, and the node handle is returned to the creator. The creator can increase the ref count by calling xnProductionNodeAddRef() or xn::ProductionNode::AddRef(). Once someone holding a node does not need it anymore, it may call xnProductionNodeRelease() or xn::ProductionNode::Release(). If a node's reference count reaches 0, the node will be removed from context and destroyed.

Note:
An application may not assume anything about the existence of a node once the node is unreferenced. The node might be destroyed, but it also might still exist, if some other node is using it. In any case it is forbidden for an application to use the node handle once it was unreferenced.

Please note that referencing a Node Info object of an existing node also counts as a reference to this node. For example, if the application called xnEnumerateExistingNodes() (xn::Context::EnumerateExistingNodes()), and received a Node Info List that contains this node, then the node reference count was increased by 1. The application must free the list in order to unref each node in that list. This can be done by calling xnNodeInfoListFree() (in C++, the destructor of xn::NodeInfoList does this for you).

In any case, shutting down OpenNI by calling xnShutdown() (xn::Context::Shutdown()) destroys all nodes, even ones that have a reference count higher than 1.