Difference between revisions of "Uno/Cpp/Snippet/Object Lifecycle"
From Apache OpenOffice Wiki
m (Extract from Cpp Uno introduction) |
SergeMoutou (Talk | contribs) m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | < | + | <source lang="cpp"> |
using namespace ::com::sun::star::uno; | using namespace ::com::sun::star::uno; | ||
Line 12: | Line 12: | ||
// release does a delete this, the object is destroyed; | // release does a delete this, the object is destroyed; | ||
} | } | ||
− | </ | + | </source> |
<noinclude>[[Category:Snippet]][[Category:Uno]][[Category:Cpp]][[Category:Uno:Cpp:Snippet]]</noinclude> | <noinclude>[[Category:Snippet]][[Category:Uno]][[Category:Cpp]][[Category:Uno:Cpp:Snippet]]</noinclude> | ||
− | 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). | + | 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 <idl>com.sun.star.uno.XInterface</idl>. The above code has no resource leak, it is perfectly OK (though certainly not very useful). |
Latest revision as of 16:17, 11 May 2009
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 com.sun.star.uno.XInterface. The above code has no resource leak, it is perfectly OK (though certainly not very useful).