BMessage* message = new BMessage(); message->AddRef(); // increment reference count
BMessage* message = new BMessage(); message->AddRef(); // increment reference count if (message->CountNames(B_ANY_TYPE) == 0) { message->Release(); // release memory if no names }In this example, the reference count is used to determine when the message object can be safely deleted and its memory released. The CountNames() function returns the number of names (keys) in the message, and if it is found to be 0, then the Release() function is called to decrement the reference count and delete the object if the count is now 0. Package library: Messaging Kit (libbe.so)