mfc框架下osg的内存泄露问题(转)
2010-11-07 17:23
267 查看
这个问题其实是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
感谢原作者
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
感谢原作者
相关文章推荐
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- vs2008下MFC内存泄露问题一点经验
- 关于 MFC 中 CString 内存泄露的问题
- MFC和opencv一起使用时会莫名奇妙出现内存泄露问题
- OSG嵌入到MFC中报内存泄露
- mfc非模态子对话框调用内存泄露问题
- ACE 与MFC 混合使用 内存泄露问题
- OGRE与MFC结合产生的内存泄露问题
- 关于 MFC 中 CString 内存泄露的问题
- MFC内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- MFCLinkCtrl 的内存泄露问题
- 160715、在web.xml中注册IntrospectorCleanupListener解决Quartz等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决spring mvc等框架可能产生的内存泄露问题
- 在web.xml中注册IntrospectorCleanupListener监听器以解决struts等框架可能产生的内存泄露问题