[osg-users] how to release loaded model

2008-07-24 Thread su hu
Hi all.

I need to release loaded model and reload other model. I did as follow:


osgViewer::ViewerViewer;
osg::ref_ptrosg::Group root   =  new osg::Group;
osg::ref_ptrosg::Group ModelRoot =  new osg::Group;
osg::ref_ptrosg::Node loadedModel;
...
Viewer.setSceneData(root.get());
root-addChild(ModelRoot.get());
...

//in frame loop
.
switch(CMD)
{
case LOAD_SCENE:
{

loadedModel = osgDB::readNodeFile(CMD_SceneFileName);

if (loadedModel.valid())
{
ModelRoot-addChild(loadedModel.get());
}
break;
}
case RELEASE_SCENE:
{
if(ModelRoot.valid())
{
ModelRoot-removeChildren(0,ModelRoot-getNumChildren());
}

loadedModel.release();

break;
}

}

...

The loadedModel is added to ModelRoot and is not added to any other group.

Models could be loaded and released. But I found used memory was not
reduced at all after RELEASE_SCENE was executed.  After loading and
releasing several times, used memory is more than 1GB and program is
freezed.  I want to know the reason and how to improve it.

Much appreciation to any reply.


Regards,

Su Hu
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] how to release loaded model

2008-07-24 Thread Robert Osfield
Hi Su,

You shouldn't be called ref_ptr.release() in this context, you should
be just setting the ref_ptr to null.

ref_ptr::release() is a specialist helper method with does an
unref_noDelete on the referenced object - it deliberately doesn't
delete the object that it's unrefecing.  This functionality is
required for functions that use ref_ptr locally but then have to
pass a C* point of the object.

Robert.

On Thu, Jul 24, 2008 at 10:45 AM, su hu [EMAIL PROTECTED] wrote:
 Hi all.

 I need to release loaded model and reload other model. I did as follow:


 osgViewer::ViewerViewer;
 osg::ref_ptrosg::Group root   =  new osg::Group;
 osg::ref_ptrosg::Group ModelRoot =  new osg::Group;
 osg::ref_ptrosg::Node loadedModel;
 ...
 Viewer.setSceneData(root.get()
 );
 root-addChild(ModelRoot.get());
 ...

 //in frame loop
 .
 switch(CMD)
 {
 case LOAD_SCENE:
 {

 loadedModel = osgDB::readNodeFile(CMD_SceneFileName);

 if (loadedModel.valid())
 {
 ModelRoot-addChild(loadedModel.get());
 }
 break;
 }
 case RELEASE_SCENE:
 {
 if(ModelRoot.valid())
 {
 ModelRoot-removeChildren(0,ModelRoot-getNumChildren());
 }

 loadedModel.release();

 break;
 }

 }

 ...

 The loadedModel is added to ModelRoot and is not added to any other group.

 Models could be loaded and released. But I found used memory was not
 reduced at all after RELEASE_SCENE was executed.  After loading and
 releasing several times, used memory is more than 1GB and program is
 freezed.  I want to know the reason and how to improve it.

 Much appreciation to any reply.


 Regards,

 Su Hu
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] how to release loaded model

2008-07-24 Thread su hu
Hi Robert,

I set ref_ptr to null. It works well. Thanks a lot.

Best Regards,

Su Hu

2008/7/24 Robert Osfield [EMAIL PROTECTED]:

 Hi Su,

 You shouldn't be called ref_ptr.release() in this context, you should
 be just setting the ref_ptr to null.

 ref_ptr::release() is a specialist helper method with does an
 unref_noDelete on the referenced object - it deliberately doesn't
 delete the object that it's unrefecing.  This functionality is
 required for functions that use ref_ptr locally but then have to
 pass a C* point of the object.

 Robert.

 On Thu, Jul 24, 2008 at 10:45 AM, su hu [EMAIL PROTECTED] wrote:
  Hi all.
 
  I need to release loaded model and reload other model. I did as follow:
 
 
  osgViewer::ViewerViewer;
  osg::ref_ptrosg::Group root   =  new osg::Group;
  osg::ref_ptrosg::Group ModelRoot =  new osg::Group;
  osg::ref_ptrosg::Node loadedModel;
  ...
  Viewer.setSceneData(root.get()
  );
  root-addChild(ModelRoot.get());
  ...
 
  //in frame loop
  .
  switch(CMD)
  {
  case LOAD_SCENE:
  {
 
  loadedModel = osgDB::readNodeFile(CMD_SceneFileName);
 
  if (loadedModel.valid())
  {
  ModelRoot-addChild(loadedModel.get());
  }
  break;
  }
  case RELEASE_SCENE:
  {
  if(ModelRoot.valid())
  {
  ModelRoot-removeChildren(0,ModelRoot-getNumChildren());
  }
 
  loadedModel.release();
 
  break;
  }
 
  }
 
  ...
 
  The loadedModel is added to ModelRoot and is not added to any other
 group.
 
  Models could be loaded and released. But I found used memory was not
  reduced at all after RELEASE_SCENE was executed.  After loading and
  releasing several times, used memory is more than 1GB and program is
  freezed.  I want to know the reason and how to improve it.
 
  Much appreciation to any reply.
 
 
  Regards,
 
  Su Hu
  ___
  osg-users mailing list
  osg-users@lists.openscenegraph.org
 
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
 
 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] how to release loaded model

2008-07-24 Thread su hu
Hi Ümit

Thanks for you suggestion. There are several scene models in our application
and they are large. So we have to release them when we start a new scene.

Thanks again.

Kind Regards,

Su Hu

2008/7/24 Ümit Uzun [EMAIL PROTECTED]:

 Hi Su,

 I think you shoul use Switch node to change the model. It is so easy and
 useful. Look at the simple example.

 2008/7/24 su hu [EMAIL PROTECTED]:

 Hi all.

 I need to release loaded model and reload other model. I did as follow:


 osgViewer::ViewerViewer;
 osg::ref_ptrosg::Group root   =  new osg::Group;
 osg::ref_ptrosg::Group ModelRoot =  new osg::Group;
 osg::ref_ptrosg::Node loadedModel;
 ...
 Viewer.setSceneData(root.get());
 root-addChild(ModelRoot.get());
 ...

 //in frame loop
 .
 switch(CMD)
 {
 case LOAD_SCENE:
 {

 loadedModel = osgDB::readNodeFile(CMD_SceneFileName);

 if (loadedModel.valid())
 {
 ModelRoot-addChild(loadedModel.get());
 }
 break;
 }
 case RELEASE_SCENE:
 {
 if(ModelRoot.valid())
 {
 ModelRoot-removeChildren(0,ModelRoot-getNumChildren());
 }

 loadedModel.release();

 break;
 }

 }

 ...

 The loadedModel is added to ModelRoot and is not added to any other
 group.

 Models could be loaded and released. But I found used memory was not
 reduced at all after RELEASE_SCENE was executed.  After loading and
 releasing several times, used memory is more than 1GB and program is
 freezed.  I want to know the reason and how to improve it.

 Much appreciation to any reply.


 Regards,

 Su Hu

 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] how to release loaded model

2008-07-24 Thread Jean-Sébastien Guay

Hello Robert,


ref_ptr::release() is a specialist helper method with does an
unref_noDelete on the referenced object - it deliberately doesn't
delete the object that it's unrefecing.  This functionality is
required for functions that use ref_ptr locally but then have to
pass a C* point of the object.


I have seen this confusion before from people used to Win32 
programming... In MFC (I believe), calling release() on something means 
you don't want to use it anymore, and you want it to release its 
resources (kind of like calling delete on a pointer, but it's a C API so 
there are no destructors, hence the release() function). So it means 
exactly the opposite of what it means in OSG.


Kind of ironic, but perhaps that just means that people need to read the 
API documentation a bit before using a method in their code, because it 
might not do what they assume it does.


J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org