Ismail Pazarbasi wrote:
small correction, if you don't misunderstand; that will not decrease
reference count, since ptr is void* and has no connection whatsoever
with pointee (osg::Referenced). In following case:

osg::ref_ptr<osg::Node> pnode = new osg::Node;
void* ptr = pnode;
ptr = NULL;
(this is what I understood)

Right.  Sorry, I misunderstood the original message.


Rabbi, once you get raw pointer from smart pointer, you take
responsibility of reference counting (and of course, C++ scoping
rules). You may pass that pointer around, but you should be careful
with reference counting and scope that osg::ref_ptr<T> was declared.

Exactly right.


Bottom line is; use smart pointers instead of raw pointers and be
explicit about conversions. Respect scope of smart pointer, because it
can't know what you do with the raw pointer once you obtain it.

Sometimes it's more convenient to temporarily use a generic pointer (as a local variable inside a single function, for example). This is fine, as long as you know the object is going to be valid during the course of that function. If you need to keep a reference to the object for any length of time (a class member, for example), use a ref_ptr.

--"J"

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to