Hello Gianni,

In the related examples I see an osgWidget::WindowManager instance is created 
on the heap but never deleted explicitly. Is the associated viewer responsible 
of the WindowManager deletion or should I delete it somewhere?

Like most objects in OSG, the WindowManager is reference-counted. As long as its reference count falls to 0 at some point, it will be deleted.

In the case of the osgWidget examples, for instance I took a look at osgwidgetwindow, the window manager is added as a child of a camera. any subclass of osg::Group manages its children in an std::vector of osg::ref_ptrs, so the window manager will be reference counted. When the camera is deleted, it will decrement the reference count of all its children, so the window manager will be deleted by cascade effect (if no other reference to it exists).

So the flow is:

int main(int argc, char** argv)
{

  osgWidget::WindowManager* wm = ...;
  // wm's reference count is 0, see ctor of osg::Referenced

  // ...

  camera->addChild(wm);
  // wm's reference count becomes 1

  // ...
  group->addChild(camera);
  // ...
  viewer.setSceneData(group);

  return viewer.run();
}

// At this point, the viewer goes out of scope (it's on the stack) so
// its destructor is called. Its destructor calls the destructor of all
// member variables, including its camera and its scene data which are
// stored in ref_ptrs. Since the scene (the "group" variable above) is
// deleted, all its children have their reference count decremented, so
// the WindowManager's reference count becomes 0, and it is deleted too.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [email protected]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to