c - 如何使用 CLion 在 MacOS Big Sur 上查看内存泄漏?

标签 c memory-leaks valgrind clion leak-sanitizer

我不知道如何使用 CLion 在 MacOS Big Sur 上使用 CLion 看到内存泄漏,我已经尝试过以下方法:

  • Valgrind - 与 Big Sur 不兼容
  • 来自 Clang 的 Leak Sanitizer - 根据来自 CLion 的支持人员的说法,它显然与 MacOS 不兼容
  • 在 CLion 里面,我在 CMakeLists.txt 中写了这个命令:
       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
    
    然后我在首选项菜单中写了 -> 地址 sanitizer 部分的 sanitizer :
       detect_stack_use_after_return=1
    
    基于 CLion 支持页面,他们说 Leak Sanitizer 包含在 Address sanitizer 中。
  • 最佳答案

    通常你可以在编译期间使用 libasan (https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer) 但是在 MacOS 上有一些额外的步骤:
    https://clang.llvm.org/docs/AddressSanitizer.html(在此页面上搜索“MacOS”以获得概览):

    Memory leak detection

    For more information on leak detector in AddressSanitizer, see LeakSanitizer. The leak detection is turned on by default on Linux, and can be enabled using ASAN_OPTIONS=detect_leaks=1 on macOS; however, it is not yet supported on other platforms.


    来源:https://clang.llvm.org/docs/AddressSanitizer.html
    另见 Mac OS: Leaks Sanitizerhttps://developer.apple.com/documentation/xcode/diagnosing_memory_thread_and_crash_issues_early

    关于c - 如何使用 CLion 在 MacOS Big Sur 上查看内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66599589/

    相关文章:

    c - 错误 : wide character array initialized from incompatible wide string

    python - 获取python应用程序内存使用情况

    ios - ABPersonCopyImageData 泄漏

    android - 为什么 Rxjava 会导致内存泄漏

    c - Valgrind 和 FCGI : How to free all memory correctly after use

    c - 列与行的二维数组初始化

    php - 从其他用户那里获取节奏盒信息

    c - 为什么会泄漏内存?

    c++ - std::string operator+() 内存泄漏?

    c - 我是否必须考虑控制流图中的预处理器指令?