osgearth中的内存泄漏

时间:2017-12-04 09:23:05

标签: mfc openscenegraph osgearth

我的目标是使用库OSGEarth制作一个可以显示模型的MFC项目" openstreetmap.earth"。我完成了这个并且可以看到地球。但是每当我关闭项目时,vs2015中的输出窗口都说程序中存在内存泄漏。

这是窗口输出:

Detected memory leaks!
Dumping objects ->
{306240} normal block at 0x00000000076902F0, 16 bytes long.
Data: <0,i             > 30 2C 69 07 00 00 00 00 00 00 00 00 00 00 00 00 
{306239} normal block at 0x0000000007692C30, 9 bytes long.
Data: <Pragma:  > 50 72 61 67 6D 61 3A 20 00 
{303648} normal block at 0x0000000007693040, 16 bytes long.
Data: < 5i             > 90 35 69 07 00 00 00 00 00 00 00 00 00 00 00 00 
{303647} normal block at 0x0000000007693590, 9 bytes long.
Data: <Pragma:  > 50 72 61 67 6D 61 3A 20 00 
{301180} normal block at 0x00000000076938B0, 16 bytes long.
 Data: <`8i             > 60 38 69 07 00 00 00 00 00 00 00 00 00 00 00 00 
{301179} normal block at 0x0000000007693860, 9 bytes long.
 Data: <Pragma:  > 50 72 61 67 6D 61 3A 20 00 
{297799} normal block at 0x0000000007691060, 16 bytes long.
 Data: <  i             > 10 10 69 07 00 00 00 00 00 00 00 00 00 00 00 00 

我检查了程序,发现当我删除这段代码m_Model = osgDB::readNodeFile(m_strModelName);时,没有更多的内存泄漏。

void COSGEarth::InitSceneGraph(void)
{
    // Init the main Root Node/Group
    m_Root = new osg::Group;
    // Load the Model from the model name, 
    //delete below line, no memory leak
    m_Model = osgDB::readNodeFile(m_strModelName);
    if (!m_Model) return;

    // Optimize the model
    osgUtil::Optimizer optimizer;
    optimizer.optimize(m_Model.get());
    optimizer.reset();

    // Add the model to the scene
    m_Root->addChild(m_Model.get());

}

我将 m_Model 定义为 osg::ref_ptr<osg::Node> m_Model 。这是智能指针。

为什么存在内存泄漏以及如何解决此问题?

以下是源代码:http://bbs.osgchina.org/forum.php?mod=attachment&aid=NzIwNnwzZWYxZDIyZjlhOGY1MWFjZjhiNGFiMWYwMTc5YmJlNXwxNTEyMzc5ODE2&request=yes&_f=.zip

1 个答案:

答案 0 :(得分:1)

我相信这些报道&#34;泄漏&#34;是误报。请参阅此主题解释原因:

http://forum.openscenegraph.org/viewtopic.php?t=1475