|
本帖最后由 tnt2pro 于 2017-12-4 17:16 编辑
我在VS2015中参考OSG中的osgviewerMFC中的代码,做了一个类似的MFC工程,想用它来加载"openstreetmap.earth"模型。虽然地球正确显示出来了,但是每次退出程序时,控制台都会报一大堆的内存泄漏,部分如下:
Detected memory leaks!
Dumping objects ->
{294608} normal block at 0x000000000785FD80, 16 bytes long.
Data: < > 90 FC 85 07 00 00 00 00 00 00 00 00 00 00 00 00
{294607} normal block at 0x000000000785FC90, 9 bytes long.
Data: <Pragma: > 50 72 61 67 6D 61 3A 20 00
{292519} normal block at 0x0000000007861590, 16 bytes long.
Data: <@ > 40 15 86 07 00 00 00 00 00 00 00 00 00 00 00 00
{292518} normal block at 0x0000000007861540, 9 bytes long.
Data: <Pragma: > 50 72 61 67 6D 61 3A 20 00
{290421} normal block at 0x000000000785EA20, 16 bytes long.
Data: < > D0 E9 85 07 00 00 00 00 00 00 00 00 00 00 00 00
{290420} normal block at 0x000000000785E9D0, 9 bytes long.
Data: <Pragma: > 50 72 61 67 6D 61 3A 20 00
{288327} normal block at 0x000000000785F560, 16 bytes long.
Data: < > 10 F5 85 07 00 00 00 00 00 00 00 00 00 00 00 00
{288326} normal block at 0x000000000785F510, 9 bytes long.
Data: <Pragma: > 50 72 61 67 6D 61 3A 20 00
{284367} normal block at 0x0000000009D91600, 16 bytes long.
Data: < > B0 ED D8 09 00 00 00 00 00 00 00 00 00 00 00 00
{284366} normal block at 0x0000000009D8EDB0, 9 bytes long.
将程序一段一段注释后发现,是程序中这句话引起的内存泄漏:m_Model = osgDB::readNodeFile(m_strModelName);。通过百度得知,这个地方使用的是智能指针,按理说是不应该出现内存泄漏的。更奇怪的是,如果我将加载的模型从"openstreetmap.earth"替换成"cow.osg"后,就不会出现内存泄漏了~~
osg和osge我都是使用的这个帖子:http://bbs.osgchina.org/forum.ph ... amp;_dsign=e6aac0cc 这位大大提供的。
这个问题折腾了好几天了,希望论坛的各位大大帮我看看到底是为什么,谢谢了。
源代码:http://bbs.osgchina.org/forum.php?mod=attachment&aid=NzIwNnxiOWY3NjJkNmM3ZDM1ZmJhNWIzNzU2MDNjMDYxZGZhNHwxNzMyNDEwOTA4&request=yes&_f=.zip
|
|