Thanks Simon,
I think you are right. In my application, the member pointers causing the problem are really 'users' rather than 'owners'. One of my objectives is to protect myself from my own programming, and so avoiding raw pointers and moving into a style of programming that is more like Java or C# helps me a lot. If I had noticed the existance of osg::observer_ptr earlier, I think maybe I would have used it instead of ref_ptr for the class members in this case, and thus avoided the problem. On the other hand, if I had done that, my understanding of the problem would now be less complete ;-)
Chris.

Date: Tue, 18 Nov 2008 23:37:00 +0000
From: "Simon Hammett" <[EMAIL PROTECTED]>
Subject: Re: [osg-users] A very simple ref_ptr memory leak example.
To: "OpenSceneGraph Users" <[email protected]>
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

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

Reply via email to