mfc框架下osg的内存泄露问题(转)


这个问题其实是mfc的一种误报,osg有自己的内存管理方式,但是mfc不知道,
MFC自作主张的认为发生了内存泄露,实际上内存并不是没有释放,osg的内存引用释放是在VC报内存泄露之后释放,内存泄露:CrtDumpMemoryLeaks()是在mfc71d.dll(8.0,9.0同样)卸载时被调用的,如果这个时候osgd.dll还没有卸载,那么在osg中new的全局变量也就还没有释放,所以MFC会认为产生了内存泄露。

一种解决办法是将Mfc71d.dll在osg之前被链接,这样程序运行时MFC71d就会早于osg加载,也就晚于osg卸载。具体设置如下:
i) in the General tab, switch "Use MFC in a shared DLL" to "Use Standard Windows Libraries"
ii) in the C/C++/Preprocessor tab, add _AFXDLL to the preprocessor definitions
iii) in the Linker/Input tab, add mfc71d.lib anywhere before osgd.lib

通过以上设置,即可解决上述问题

将工程设置为 Use Multi-Byte Character Set
在Unicode Character Set方式下:可能会出现以下错误:
error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用

转自:http://bbs.vrchina.net/viewthread.php?tid=13868

感谢原作者

posted @ 2010-11-07 17:23  北山愚公*  阅读(944)  评论(0编辑  收藏  举报