链接 POCO C++库造成大量内存泄漏
我刚刚开始尝试将 Poco C++ 库与我们的游戏引擎集成,但是每次链接时/usr/lib/libPocoFoundation.so 我的程序突然出现 51 处内存泄漏。删除链接选项可以消除所有泄漏(它们都不是来自我的代码)。即使我从 c++ 文件中删除所有 Poco #include
,也会发生这种情况。
我怀疑 Poco 的基础(核心)方法是否真的存在 51 处内存泄漏 - 搜索他们的论坛没有发现任何内容,而且我确信其他用户会注意到如此明显的事情。我认为这更可能是我如何链接到 Poco 的问题?
我在 Ubuntu 11 上,使用 Code::Blocks 作为 IDE,使用 g++ 4.5.2 进行构建,并从 ubuntu ppa 获取 Poco 1.3.6p1-1build1 (sudo apt-get install libpoco-dev libpoco-doc )。
非常欢迎任何有关问题所在的建议!我唯一能想到的是我没有正确链接 Poco。
可能相关:c-poco- lib-linking-error-when-trying-static-linking-vs9-express 提到了有关“添加预处理器标志 Foundation_EXPORTS POCO_STATIC”的内容PCRE_STATIC” - 那会做什么?我在 Poco 参考页面上看不到任何有关如何正确链接 Poco 的信息。
I've just started trying to integrate the Poco C++ Library with our game engine, however every time I link /usr/lib/libPocoFoundation.so my program suddenly has 51 memory leaks. Removing the link option gets rid of all the leaks (none of them are from my code). This happens even if I remove all Poco #include
s from my c++ files.
I doubt there are really 51 memory leaks with Poco's Foundation (core) methods - searching their forums didn't reveal anything, and I'm sure other users would notice something this glaring. I think it is more likely a problem with how I'm linking to Poco?
I'm on Ubuntu 11, using Code::Blocks for an IDE, g++ 4.5.2 to build, and fetched Poco 1.3.6p1-1build1 from the ubuntu ppa (sudo apt-get install libpoco-dev libpoco-doc
).
Any suggestions on what the problem could be are most welcome! The only thing I can think of is that I'm not linking Poco correctly.
Possibly related: The OP at c-poco-lib-linking-error-when-trying-static-linking-vs9-express mentions something about "Added Preprocessor flags Foundation_EXPORTS POCO_STATIC PCRE_STATIC" - what would that do? I can't see any information on the Poco reference pages about how to correctly link Poco.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你没有说哪个工具告诉你有内存泄漏,但我假设它是 valgrind,因为你使用的是 Ubuntu。
如果即使您没有调用任何 POCO 方法也会发生泄漏,那么这些很可能是在 POCO 库的静态初始化期间发生的一次性分配,无论出于何种原因,这些分配都不会在以后被拆除。
虽然这对图书馆来说并不是特别好的行为,但它并不是致命的。您应该担心的泄漏是那些会重复发生并逐渐消耗内存的泄漏。
我建议暂时使用 valgrind --gen-suppressions=all 来生成一次性泄漏的抑制(特别好,因为您没有调用任何 POCO 方法)。然后,查看 POCO 库,看看您是否可以找出为什么这些分配没有在 .fini 时间展开。如果可以的话,那就太好了,让 POCO 人员修复你的问题,然后你就可以删除你的抑制条目了。如果没有,请将它们保留下来,这样这些“误报”就不会干扰在代码中查找真正有害的内存泄漏。
You don't say what tool is telling you that you have memory leaks, but I'm going to presume that it is valgrind since you are on Ubuntu.
If the leaks occur even if you aren't calling any POCO methods, then it is likely that these are one-off allocations occurring during the static initialization of the POCO library that for whatever reason are not being torn down later.
While that isn't particularly great behavior on the part of a library, it is not fatal. The leaks that you should be worried about are ones that will occur repeatedly and will gradually consume memory.
I'd recommend using
valgrind --gen-suppressions=all
to generate suppressions for the one time leaks for now (especially good that you aren't calling any POCO methods). Then, have a look at the POCO library and see if you can figure out why these allocations aren't being unwound at .fini time. If you can, great, let the POCO people have your fixes, and then you can take down your suppression entries. If not, leave them in so these 'false positives' don't interfere with finding truly harmful memory leaks in your code.某些对象必须通过调用“release”方法来释放,
下面是 doc poco 的摘录
“
DOMObject 定义了 DOM 实现中的内存管理规则。违反下面概述的这些规则会导致内存泄漏或悬空指针。
每个由 new 或工厂方法创建的对象(例如,Document::create*)在不再需要时必须通过调用 release() 或 autoRelease() 来释放。 ”
Some objects must be deallocated by calling method "release"
Below is an extract from a doc poco
"
DOMObject defines the rules for memory management in this implementation of the DOM. Violation of these rules, which are outlined in the following, results in memory leaks or dangling pointers.
Every object created by new or by a factory method (for example, Document::create*) must be released with a call to release() or autoRelease() when it is no longer needed. "