[osg-users] ref_ptr, ptr and leaking question (quite simple)

Gordon Tomlinson gordon.tomlinson at sensor.com
Sat Jul 26 08:52:03 PDT 2008


No leak, the reference count is Zero after you create the instance 

The count is only incremented when you add the instance to a parent

So in your example below the count will be 1 after viewer.setSceneData(g)

-----Original Message-----
From: osg-users-bounces at lists.openscenegraph.org
[mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Ariasgore
Sent: Saturday, July 26, 2008 5:23 AM
To: OpenSceneGraph Users
Subject: [osg-users] ref_ptr, ptr and leaking question (quite simple)

I have some novoice question about the use of pointers as short-time
reference. As in the tutorial book described all objects deriving from
osg::Referenced should be used with ref_ptr for proper use.
But even in the book and in some tutorials there are many uses of the plain 
c++ pointer without the reference use of ref_ptr.
There is where I have one question, if I develop in VisualStudio for
instance and write some code like:

osg::Geode * g = new osg::Geode;

Doesn't I have a ref count of 2 for g? Whild would result in a leak since I
never delete the g pointer manually?

If this above is true and the programm is running as a childprocess of my
IDE (since I have debugging and stacktracing and so on), don't I create some
leaking beyond the lifetime of the programm? I am not quite sure if the
memory is cleaned after finishing the programm or the whole IDE.


osg-users mailing list
osg-users at lists.openscenegraph.org

More information about the osg-users mailing list