On 17/03/11 11:33 , Yasser Asmi wrote: > Thanks. That makes sense but I still have a question. > > If I am createing a new OSG object in my code, say osg:Geometry, and I know > it will be > passed to a osg method at some point. How do I know if I should or should > not wrap it > in ref_ptr? I'd think we should wrap it. But I have seen a lot of examples > that do > not. I am concerned about memory leaks.
Most of the examples create OSG objects, pass them on to another OSG object (where it will be reference counted) and do not care about them afterwards. If you keep a reference to the object (as well as pass it on to another OSG object) then you must use a ref_ptr, otherwise it can be deleted and you end up with a dangling object. This is okay: void createStuff(osg::Group* group) { // This is okay, the drawable will be owned by the group osg::Geometry* drawable = new osg::Geometry(); group->addChild(drawable); } But this is not: class Stuff { osg::Geometry* _drawable; void createStuff(osg::Group* group) { // Bad things waiting to happen... _drawable = new osg::Geometry(); group->addChild(_drawable); } } Cheers, /ulrich _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org