[osg-users] how to release loaded model

su hu tttsuhu at gmail.com
Thu Jul 24 03:28:05 PDT 2008


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 <umituzun84 at gmail.com>:

> 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 <tttsuhu at gmail.com>:
>
>> Hi all.
>>
>> I need to release loaded model and reload other model. I did as follow:
>>
>>
>> osgViewer::Viewer    Viewer;
>> osg::ref_ptr<osg::Group> root           =  new osg::Group;
>> osg::ref_ptr<osg::Group> ModelRoot =  new osg::Group;
>> osg::ref_ptr<osg::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 at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080724/4dda524b/attachment-0003.htm>


More information about the osg-users mailing list