2008/11/18 Chris Denham <[EMAIL PROTECTED]>: > Thanks for the tips everyone. > I suppose as Paul suggests, it's best to avoid doing things that hurt. > The problem is that when we accidentally implemented this pattern in a > more complex application, it was a bit fiddly to track down. I only > noticed the problem because of the memory leak that resulted from it. > I suppose the lesson I learn is that I need to be more careful when > using ref_ptr than blindly applying it to every Referenced object > whose lifetime is less than obvious to me. Which I have to confess, > was my previous rather flawed logic. > Chris. >
Don't forget that these reference counted pointers (of all types) actually conflate two completely different concepts. That is: Ownership - vs - Uses / Has a relationship with If you break down your use of these pointers into these two concepts it's usually easy to work out what to do. Many objects make use of many different other objects, but ownership is usually a much more straight forward proposition. i.e. It rarely makes sense for object A to own object B and object B to own object A. but it's quite common for A to use B and B to use A. In general, use ref_ptr for owner ship and raw pointer (or better yet references) for uses. Of course there are exceptions to every rule of thumb, but the only times I've seen significant differences are when people are implementing interpreted languages and other relatively obscure corner cases. -- The truth is out there. Usually in header files. _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

