gperftools中明显的内存泄漏
Apparent memory leak in gperftools
这个是在运行使用地址清理器构建的程序时出现的,这让我很好奇。
gperftools源代码包含以下函数:
void MallocExtension::Register(MallocExtension* implementation) {
InitModule();
// When running under valgrind, our custom malloc is replaced with
// valgrind's one and malloc extensions will not work. (Note:
// callers should be responsible for checking that they are the
// malloc that is really being run, before calling Register. This
// is just here as an extra sanity check.)
if (!RunningOnValgrind()) {
current_instance = implementation;
}
}
InitModule
定义如下
static void InitModule() {
if (current_instance != NULL) {
return;
}
current_instance = new MallocExtension; // pointless?
#ifndef NO_HEAP_CHECK
HeapLeakChecker::IgnoreObject(current_instance);
#endif
}
我们的地址清理器(当然不是 valgrind(抱怨MallocExtension
对象的内存泄漏。显然,这是对的。但是,为什么首先会出现这种分配呢?
我拒绝认为开发自己的记忆分配器的人会犯这样一个微不足道的错误。还有对瓦尔格林德的明确检查。那么分配的目的是什么呢?
是的,在各种谷歌代码(即不仅仅是gperftools(中,故意泄漏启动时错误定位的单例对象是很常见的。思维既不是初始化,也不是破坏顺序是明确的。因此,试图在进程关闭时释放此类单例是要求各种超级难以跟踪的问题。
更多在这里: https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
相关文章:
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 尽管遵循了规则,内存泄漏在哪里
- 为什么调用堆栈数组会导致内存泄漏
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 使用模板类的自定义列表类型中的内存泄漏
- 为什么以下C++代码中存在内存泄漏?
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- 我是否生成线程并导致内存泄漏?
- 多线程程序中出现意外的内存泄漏
- 为什么此函数会导致内存泄漏?
- 在 C++ 库中使用cythonized python时内存泄漏
- 需要帮助查找内存泄漏
- 瓦尔格林德的内存泄漏使用新的
- 无法找出我的代码中的内存泄漏
- C++ 结构内部的unordered_map会导致内存泄漏问题吗?
- 可视化 使用 VS Code 查找C++应用程序中的内存泄漏
- Shared_ptr双链接列表内存泄漏
- C++ 在类中使用常量引用文本时 O2 内存泄漏