Linux中的内存泄漏检查工具出现问题 [英] Problem with memory leak check tools in Linux

查看:434
本文介绍了Linux中的内存泄漏检查工具出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)是否还有任何名为Boehmgc的内存泄漏工具?与其他工具相比,该工具如何?

1) Is there also any memory leak tool called Boehmgc? How is that tool compared to others?

2)我用过LeakTracermudflapValgrind.但是不幸的是,LeakTracer的缺点是占用内存(在启动时先池化大量内存,然后分配内存),那么还有什么选择呢?

2) I have used LeakTracer, mudflap and Valgrind. But unfortunately LeakTracer has the disadvantage of memory hogging (pooling a lot of memory at start and then allocating it), so what are the alternatives?

推荐答案

Boehm GC 是垃圾收集器,类似于Java中的垃圾收集.您提到的其他工具旨在针对泄漏警告,以便您可以采取纠正措施.垃圾回收旨在在程序运行时查找并恢复不再使用的分配.示例(来自维基百科页面):

Boehm GC is a garbage collector, similar to the garbage collection in Java. The other tools you mention are designed to warn you about leaks, such that you can take corrective action. Garbage collection is designed to find and recover no-longer used allocations, as the program runs. Example (from wikipedia page):

#include <assert.h>
#include <stdio.h>
#include <gc.h>

int main(void)
{
    int i;

    GC_INIT();
    for (i = 0; i < 10000000; ++i)
    {
        // GC_MALLOC instead of malloc
        int **p = GC_MALLOC(sizeof(int *));
        int *q = GC_MALLOC_ATOMIC(sizeof(int));

        assert(*p == 0);
        // GC_REALLOC instead of realloc
        *p = GC_REALLOC(q, 2 * sizeof(int));
        if (i % 100000 == 0)
            printf("Heap size = %zu\n", GC_get_heap_size());
    }

    // No free()

    return 0;
}

就个人而言,在C或C ++中使用垃圾回收有一些让我感到不安的地方.对于C ++,"智能指针"是解决方法我认为,在所有权不明确的情况下(尽管您可能想知道为什么为什么在设计中不明确),以及寻求有关异常安全性的帮助(例如,现在不推荐使用的

Personally there's something about using garbage collection in C or C++ that makes me quite uneasy. For C++ "Smart pointers" are the way to go in my opinion in scenarios where ownership is unclear (although you might want to have a thing about why it's unclear in your design) and for help with exception safety (E.g. what the now deprecated std::auto_ptr was designed for)

对于检漏仪,您可以添加:

As for the leak detectors you can add:

  • ccmalloc
  • dmalloc
  • NJAMD (Not just another memory debugger)
  • mpatrol
  • YAMD (yet another malloc debugger)

到您的Linux列表中.

To your list of Linux ones.

相关的内存检查工具,但不泄漏:

Related memory checking tools, but not leaks:

这篇关于Linux中的内存泄漏检查工具出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆