Hi Rico, On 28 November 2014 at 09:07, Rico Widmer <[email protected]> wrote:
> when I use osgDB::readNodeFile() for reading a file, the function returns > a pointer to a node. The destructor of the Node class is protected and it > says that it is deleted when not referenced any more. > The destructed is deliberately made protected to prevent your from directly deleting it - this is done for almost all Objects in the OSG that should be managed via reference counting. The osg::ref_ptr<> is the safest way to manage this reference counting. > So is it enough to store the returned Node* in a ref_ptr<Node>? Such a > pointer is dereferenced automatically when going out of scope e.g. when the > object is destroyed. > Bingo, this is exactly what you are meant to do when managing most OSG objects - in particular all the scene graph nodes/state attributes/geometry etc. There are times when you can temporarily use a C pointer rather than a ref_ptr<> if you know that the object won't be deleted or leaked during that code block. In the case of being deleted on has to consider whether the object might be deleted by another thread whilst you are using a C pointer. There are also readRefNodeFile() functions that are equivalents of readNodeFile() for apps that know that the objects are being cached and used by other threads. Robert.
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

