OSG智能指针学习2

根据osg资料,所有osg场景的节点都采用引用计数方式;当引用计数为0,此对象将被自动释放;

还没看手册,VS中智能提示中有referenceCount()函数,从名字看此函数是返回引用计数;

根据资料,ref()是对节点的引用计数加1,unref()是对节点的引用计数减1;

下面测试一下;

#include 
#include 

#include 
#include 
#include 

#include 
#include 

#include 

int main()
{
	osgViewer::Viewer* viewer = new osgViewer::Viewer();
	osg::Group* root = new osg::Group();

	//创建一个节点
	osg::ref_ptr pnode;	

	//读取一个osg模型
	pnode = osgDB::readNodeFile("tree.osg");
	std::cout << "read: " << pnode->referenceCount() << std::endl;

	pnode->ref();
	std::cout << "ref: " << pnode->referenceCount() << std::endl;

	root->addChild(pnode.get())

你可能感兴趣的:(VC++,图形学和3D,智能指针,引用计数,ref,unref)