Uno/Cpp/Snippet/Object Lifecycle

From Apache OpenOffice Wiki
< Uno‎ | Cpp
Revision as of 15:08, 25 May 2007 by Kr (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[cpp] using namespace ::com::sun::star::uno;

{

   // refcount of pSimpleUnoObject is zero
   OWeakObject *pSimpleUnoObject = new ::cppu::OWeakObject();
   // ctor calls acquire, increases refcount
   Reference< XInterface > reference( (XInterface *) pSimpleUnoObject );
   // destructor of reference calls release, refcount drops to zero,
   // release does a delete this, the object is destroyed;

} cppu::OWeakObject is a very simple uno-object, that is often used as a base class for other UNO-objects, as explained below. Here it is only important to know, that it correctly implements XInterface. The above code has no resource leak, it is perfectly OK (though certainly not very useful).

Personal tools